🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(experiments): double brace in json syntax mistaken as variable (#5264)
marliessophie30c8fc22393a
diff --git a/worker/src/ee/experiments/experimentService.ts b/worker/src/ee/experiments/experimentService.tsindex 3cd3cb278c..48b056f9f8 100644--- a/worker/src/ee/experiments/experimentService.ts+++ b/worker/src/ee/experiments/experimentService.ts@@ -40,12 +40,17 @@ const replaceVariablesInPrompt = (variables: string[],): { role: string; content: string }[] => {const processContent = (content: string) => {- // Only include the variables that are in the variables array+ // Extract only relevant variables from itemInputconst filteredContext = Object.fromEntries(Object.entries(itemInput).filter(([key]) => variables.includes(key)),);- return compileHandlebarString(content, filteredContext);+ // Apply Handlebars ONLY if the content contains `{{variable}}` pattern+ if (content.includes("{{")) {+ return compileHandlebarString(content, filteredContext);+ }++ return content; // Return original content if no placeholders are found};if (typeof prompt === "string") {diff --git a/worker/src/features/utilities.ts b/worker/src/features/utilities.tsindex bc8e8499fc..a6390c43f9 100644--- a/worker/src/features/utilities.ts+++ b/worker/src/features/utilities.ts@@ -92,6 +92,11 @@ export function compileHandlebarString(handlebarString: string,context: Record<string, any>,): string {- const template = Handlebars.compile(handlebarString);- return template(context);+ try {+ const template = Handlebars.compile(handlebarString, { noEscape: true });+ return template(context);+ } catch (error) {+ logger.info("Handlebars compilation error:", error);+ return handlebarString; // Fallback to the original string if Handlebars fails+ }}