Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(prompts): dollar sign in replaceValue breaking resolution (#6256)

Hassieb Pakzad0b173f47f771
diff --git a/packages/shared/src/server/services/PromptService/index.ts b/packages/shared/src/server/services/PromptService/index.ts
index b42c8278e0..7bdcb26796 100644
--- a/packages/shared/src/server/services/PromptService/index.ts
+++ b/packages/shared/src/server/services/PromptService/index.ts
@@ -372,7 +372,9 @@ export class PromptService {
);
const regex = new RegExp(combinedPattern, "g");
- const replaceValue = JSON.stringify(resolvedDepPrompt).slice(1, -1); // this is necessary to avoid parsing errors as resolved value is unstringified
+ const replaceValue = JSON.stringify(resolvedDepPrompt)
+ .slice(1, -1) // this is necessary to avoid parsing errors as resolved value is unstringified
+ .replace(/\$/g, "$$$$"); // Escape dollar signs in replacement string. $ has special meaning in replace(), so we need to escape it with $$. Since we're in a string that will be used as a replacement, we need to double escape it (hence $$$$)
resolvedPrompt = resolvedPrompt.replace(regex, replaceValue);
}