🪢 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(playground): enable parsing for double stringified msg array (#11400)
Nimarc50af94e91d2
diff --git a/packages/shared/src/utils/chatml/adapters/generic.ts b/packages/shared/src/utils/chatml/adapters/generic.tsindex 5a45536864..45e8284415 100644--- a/packages/shared/src/utils/chatml/adapters/generic.ts+++ b/packages/shared/src/utils/chatml/adapters/generic.ts@@ -117,11 +117,23 @@ function preprocessData(data: unknown): unknown {// Object with messages keyif (typeof data === "object" && "messages" in data) {const obj = data as Record<string, unknown>;+ let messages = obj.messages;++ // Handle double-stringified messages: { messages: "[{...}]" }+ // ClickHouse can store the array as a string due to double-stringification+ if (typeof messages === "string") {+ try {+ messages = JSON.parse(messages);+ } catch {+ // Keep as string if parse fails+ }+ }+return {...obj,- messages: Array.isArray(obj.messages)- ? obj.messages.map(normalizeGoogleMessage)- : obj.messages,+ messages: Array.isArray(messages)+ ? messages.map(normalizeGoogleMessage)+ : messages,};}diff --git a/web/src/utils/chatml/jumptoplayground.clienttest.ts b/web/src/utils/chatml/jumptoplayground.clienttest.tsindex 239dc0bfca..19f16cf357 100644--- a/web/src/utils/chatml/jumptoplayground.clienttest.ts+++ b/web/src/utils/chatml/jumptoplayground.clienttest.ts@@ -879,6 +879,40 @@ describe("Playground Jump Full Pipeline", () => {expect(firstMessage.tools![1].name).toBe("search_web");});+ it("should handle double-stringified messages array", () => {+ // ClickHouse can store messages as double-stringified:+ // { "messages": "[{\"role\":\"user\",\"content\":\"...\"}]" }+ // instead of: { "messages": [{role: "user", ...}] }+ //+ // This caused validation to fail: expected array, received string+ const input = {+ messages: JSON.stringify([+ // ← DOUBLE STRINGIFIED+ { role: "system", content: "You are a helpful assistant." },+ { role: "user", content: "Hello" },+ { role: "assistant", content: "Hi there!" },+ { role: "user", content: "How are you?" },+ ]),+ };++ const ctx = {};+ const inResult = normalizeInput(input, ctx);++ expect(inResult.success).toBe(true);+ if (!inResult.data) throw new Error("Expected data to be defined");++ const playgroundMessages = inResult.data+ .map(convertChatMlToPlayground)+ .filter((msg) => msg !== null);++ // Must have all 4 messages for playground button to be enabled+ expect(playgroundMessages).toHaveLength(4);+ expect(playgroundMessages[0]?.type).toBe("public-api-created");+ if (playgroundMessages[0] && "role" in playgroundMessages[0]) {+ expect(playgroundMessages[0].role).toBe("system");+ }+ });+it("should respect includeOutput flag when jumping to playground, default to no output added", () => {// kinda a bad test mocking UI behavior and not really testing the UI.// but it should illustrate that the default behavior is to not include output! and document that.