Skip to content

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

fix(playground): don't crash if tools not stringified (#10189)

Nimar038b2befeb85
diff --git a/web/src/utils/chatml/jumptoplayground.clienttest.ts b/web/src/utils/chatml/jumptoplayground.clienttest.ts
index ae4ff4689e..cb7b49d0ee 100644
--- a/web/src/utils/chatml/jumptoplayground.clienttest.ts
+++ b/web/src/utils/chatml/jumptoplayground.clienttest.ts
@@ -429,6 +429,82 @@ describe("Playground Jump Full Pipeline", () => {
}
});
+ it("should stringify multimodal array content in tool results", () => {
+ // This format appears in some OpenAI traces where tool results have
+ // complex nested structures with type/text fields
+ const input = {
+ tools: [
+ {
+ type: "function",
+ function: {
+ name: "get_user_contact_information",
+ description: "Get user contact info",
+ parameters: {},
+ },
+ },
+ ],
+ messages: [
+ {
+ role: "assistant",
+ content: "",
+ tool_calls: [
+ {
+ id: "call_user_info",
+ type: "function",
+ function: {
+ name: "get_user_contact_information",
+ arguments: {},
+ },
+ },
+ ],
+ },
+ {
+ role: "tool",
+ content: [
+ {
+ type: "text",
+ text: {
+ userInformation: {
+ firstName: "John",
+ lastName: "Doe",
+ email: "[email protected]",
+ },
+ },
+ },
+ ],
+ tool_call_id: "call_user_info",
+ },
+ ],
+ };
+
+ const ctx = { framework: "openai" };
+ const inResult = normalizeInput(input, ctx);
+ expect(inResult.success).toBe(true);
+
+ // Convert all messages to playground format
+ const playgroundMessages = inResult
+ .data!.map(convertChatMlToPlayground)
+ .filter((msg) => msg !== null);
+
+ // Find the tool result message
+ const toolResult = playgroundMessages.find(
+ (msg) => msg?.type === "tool-result",
+ );
+
+ expect(toolResult).toBeDefined();
+ if (toolResult && "content" in toolResult) {
+ // CRITICAL: Content must be stringified, not left as array/object
+ // Otherwise CodeMirror will throw "value must be typeof string but got object"
+ expect(typeof toolResult.content).toBe("string");
+
+ // Verify it's valid JSON string
+ const parsed = JSON.parse(toolResult.content);
+ expect(Array.isArray(parsed)).toBe(true);
+ expect(parsed[0].type).toBe("text");
+ expect(parsed[0].text.userInformation.firstName).toBe("John");
+ }
+ });
+
it("should extract tools from Microsoft Agent Framework metadata", () => {
// Microsoft Agent Framework stores tools in metadata.attributes["gen_ai.tool.definitions"]
const input = [
diff --git a/web/src/utils/chatml/playgroundConverter.ts b/web/src/utils/chatml/playgroundConverter.ts
index 0109352922..742672d331 100644
--- a/web/src/utils/chatml/playgroundConverter.ts
+++ b/web/src/utils/chatml/playgroundConverter.ts
@@ -6,6 +6,17 @@ import {
type PlaceholderMessage,
} from "@langfuse/shared";
+// convert content to string format expected by playground
+function contentToString(content: unknown): string {
+ if (typeof content === "string") {
+ return content;
+ }
+ if (content === null || content === undefined) {
+ return "";
+ }
+ return JSON.stringify(content);
+}
+
export function convertChatMlToPlayground(
msg: ChatMlMessageSchema,
): ChatMessage | PlaceholderMessage | null {
@@ -61,7 +72,7 @@ export function convertChatMlToPlayground(
return {
role: ChatMessageRole.Assistant,
- content: (msg.content as string) || "",
+ content: contentToString(msg.content),
type: ChatMessageType.AssistantToolCall,
toolCalls,
};
@@ -74,23 +85,16 @@ export function convertChatMlToPlayground(
if (toolCallId) {
return {
role: ChatMessageRole.Tool,
- content: (msg.content as string) || "",
+ content: contentToString(msg.content),
type: ChatMessageType.ToolResult,
toolCallId: toolCallId as string,
};
}
// Handle regular messages
- const content =
- typeof msg.content === "string"
- ? msg.content
- : msg.content === null || msg.content === undefined
- ? ""
- : JSON.stringify(msg.content);
-
return {
role: (msg.role as ChatMessageRole) || ChatMessageRole.Assistant,
- content,
+ content: contentToString(msg.content),
type: ChatMessageType.PublicAPICreated,
};
}