🪢 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
feat(normalize-io): use normalized parser in GA for single trace UI (#17729)
marliessophiee420aa8c8e5e
diff --git a/packages/shared/AGENTS.md b/packages/shared/AGENTS.mdindex 4d318b0b3b..973dbb7109 100644--- a/packages/shared/AGENTS.md+++ b/packages/shared/AGENTS.md@@ -100,10 +100,10 @@`@langfuse/shared/src/server/ee/ingestionMasking`,`@langfuse/shared/src/server/llm/llmText`, and`@langfuse/shared/src/utils/chatml`. The- `@langfuse/shared/src/utils/normalized-io` parser is client-safe and powers- the web "Improved Message Rendering" feature preview (the normalized Formatted- trace/observation view). Its public contract is still settling, so treat other- consumers as experimental until it stabilizes.+ `@langfuse/shared/src/utils/normalized-io` parser is client-safe and is the+ only parser behind the web Formatted trace/observation view; the legacy+ ChatML helpers remain for the session feed and the playground (for now). Its result+ type is not frozen yet, so a new consumer should expect to move with it.When changing export surfaces, keep `package.json#exports`, the relevant barrelfile (`src/index.ts`, `src/server/index.ts`, etc.), and this guide aligned indiff --git a/web/src/__tests__/server/organization-feature-flags.servertest.ts b/web/src/__tests__/server/organization-feature-flags.servertest.tsindex 47069d78ce..b9495bb538 100644--- a/web/src/__tests__/server/organization-feature-flags.servertest.ts+++ b/web/src/__tests__/server/organization-feature-flags.servertest.ts@@ -234,7 +234,6 @@ describe("organization feature preview defaults", () => {// a second preview; add that half back with the next one.modernSession: false,sessionTimeline: false,- normalizedIoPreview: false,});});@@ -495,7 +494,6 @@ describe("organization member feature preview overrides", () => {expect(row?.featurePreviews).toEqual({modernSession: true,sessionTimeline: false,- normalizedIoPreview: false,});expect(row?.user).not.toHaveProperty("featureFlags");expect(row).not.toHaveProperty("organizationIds");diff --git a/web/src/features/feature-flags/available-flags.ts b/web/src/features/feature-flags/available-flags.tsindex 49231fb5b8..6a301d08a6 100644--- a/web/src/features/feature-flags/available-flags.ts+++ b/web/src/features/feature-flags/available-flags.ts@@ -3,7 +3,6 @@ import { assertUnreachable } from "@langfuse/shared";export const featurePreviewFlags = ["modernSession","sessionTimeline",- "normalizedIoPreview",] as const;export type FeaturePreviewFlag = (typeof featurePreviewFlags)[number];@@ -39,7 +38,6 @@ export const filterFeaturePreviewFlags = (export const featurePreviewLabels = {modernSession: "Compact Session View",sessionTimeline: "Session Timeline",- normalizedIoPreview: "Improved Message Rendering",} satisfies Record<FeaturePreviewFlag, string>;export type FeaturePreviewAvailabilityContext = {@@ -54,10 +52,6 @@ export const isFeaturePreviewAvailable = (return context.v4BetaEnabled;}- if (flag === "normalizedIoPreview") {- return true;- }-return assertUnreachable(flag);};diff --git a/web/src/features/feature-flags/components/UserFeaturePreviewsPopover.clienttest.tsx b/web/src/features/feature-flags/components/UserFeaturePreviewsPopover.clienttest.tsxindex e5bf6d799b..ee8e2498a6 100644--- a/web/src/features/feature-flags/components/UserFeaturePreviewsPopover.clienttest.tsx+++ b/web/src/features/feature-flags/components/UserFeaturePreviewsPopover.clienttest.tsx@@ -124,7 +124,6 @@ describe("UserFeaturePreviewsControl", () => {featurePreviews: {modernSession: false,sessionTimeline: false,- normalizedIoPreview: false,},management: {allowed: false,@@ -152,7 +151,6 @@ describe("UserFeaturePreviewsControl", () => {featurePreviews: {modernSession: false,sessionTimeline: false,- normalizedIoPreview: false,},management: { allowed: true },});@@ -189,7 +187,6 @@ describe("UserFeaturePreviewsControl", () => {featurePreviews: {modernSession: false,sessionTimeline: false,- normalizedIoPreview: false,},management: { allowed: true },});@@ -217,7 +214,6 @@ describe("UserFeaturePreviewsControl", () => {featurePreviews: {modernSession: false,sessionTimeline: false,- normalizedIoPreview: false,},management: { allowed: true },});diff --git a/web/src/features/feature-flags/types.ts b/web/src/features/feature-flags/types.tsindex 8abd4fb1c9..75872e0912 100644--- a/web/src/features/feature-flags/types.ts+++ b/web/src/features/feature-flags/types.ts@@ -5,7 +5,6 @@ export type Flags = {[key in Exclude<Flag,| "modernSession"- | "normalizedIoPreview"| "aiGateway"| "sessionTimeline"| "traceMessages"@@ -14,7 +13,6 @@ export type Flags = {} & {// Optional while older sessions and test fixtures roll across new flags.modernSession?: boolean;- normalizedIoPreview?: boolean;aiGateway?: boolean;sessionTimeline?: boolean;traceMessages?: boolean;diff --git a/web/src/features/feature-previews/assets/improved-message-rendering-dark.svg b/web/src/features/feature-previews/assets/improved-message-rendering-dark.svgdeleted file mode 100644index 3aa5015e61..0000000000--- a/web/src/features/feature-previews/assets/improved-message-rendering-dark.svg+++ /dev/null@@ -1,31 +0,0 @@-<svg width="1200" height="700" viewBox="0 0 1200 700" fill="none" xmlns="http://www.w3.org/2000/svg">- <rect width="1200" height="700" fill="#09090B"/>- <rect x="32" y="28" width="1136" height="644" rx="18" fill="#111827" stroke="#334155" stroke-width="2"/>- <rect x="32" y="28" width="1136" height="72" rx="18" fill="#0F172A"/>- <path d="M32 100H1168" stroke="#334155" stroke-width="2"/>- <rect x="62" y="50" width="108" height="28" rx="8" fill="#172554" stroke="#60A5FA" stroke-width="2"/>- <rect x="82" y="60" width="68" height="8" rx="4" fill="#3B82F6"/>- <rect x="178" y="50" width="80" height="28" rx="8" fill="#1E293B"/>- <rect x="198" y="60" width="40" height="8" rx="4" fill="#475569"/>- <rect x="54" y="124" width="1092" height="92" rx="12" fill="#172554" stroke="#60A5FA" stroke-width="2"/>- <rect x="74" y="144" width="72" height="22" rx="6" fill="#1E3A8A"/>- <rect x="88" y="151" width="44" height="8" rx="4" fill="#60A5FA"/>- <rect x="74" y="182" width="640" height="10" rx="5" fill="#64748B"/>- <rect x="54" y="232" width="1092" height="116" rx="12" fill="#0F172A" stroke="#334155"/>- <rect x="74" y="252" width="96" height="22" rx="6" fill="#334155"/>- <rect x="88" y="259" width="60" height="8" rx="4" fill="#94A3B8"/>- <rect x="74" y="290" width="960" height="10" rx="5" fill="#475569"/>- <rect x="74" y="312" width="760" height="10" rx="5" fill="#475569"/>- <rect x="54" y="364" width="1092" height="120" rx="12" fill="#0A2E22" stroke="#34D399" stroke-width="2"/>- <rect x="74" y="384" width="128" height="22" rx="6" fill="#065F46"/>- <rect x="88" y="391" width="88" height="8" rx="4" fill="#34D399"/>- <rect x="74" y="418" width="1052" height="48" rx="8" fill="#0F3D2E"/>- <rect x="90" y="432" width="220" height="8" rx="4" fill="#34D399"/>- <rect x="90" y="448" width="420" height="8" rx="4" fill="#059669"/>- <rect x="54" y="500" width="1092" height="140" rx="12" fill="#1E1B4B" stroke="#A78BFA" stroke-width="2"/>- <rect x="74" y="520" width="112" height="22" rx="6" fill="#4C1D95"/>- <rect x="88" y="527" width="72" height="8" rx="4" fill="#A78BFA"/>- <rect x="74" y="558" width="1000" height="10" rx="5" fill="#6D28D9"/>- <rect x="74" y="580" width="880" height="10" rx="5" fill="#6D28D9"/>- <rect x="74" y="602" width="640" height="10" rx="5" fill="#4C1D95"/>-</svg>diff --git a/web/src/features/feature-previews/assets/improved-message-rendering-light.svg b/web/src/features/feature-previews/assets/improved-message-rendering-light.svgdeleted file mode 100644index 2882781131..0000000000--- a/web/src/features/feature-previews/assets/improved-message-rendering-light.svg+++ /dev/null@@ -1,31 +0,0 @@-<svg width="1200" height="700" viewBox="0 0 1200 700" fill="none" xmlns="http://www.w3.org/2000/svg">- <rect width="1200" height="700" fill="#F8FAFC"/>- <rect x="32" y="28" width="1136" height="644" rx="18" fill="white" stroke="#E2E8F0" stroke-width="2"/>- <rect x="32" y="28" width="1136" height="72" rx="18" fill="#F8FAFC"/>- <path d="M32 100H1168" stroke="#E2E8F0" stroke-width="2"/>- <rect x="62" y="50" width="108" height="28" rx="8" fill="#DBEAFE" stroke="#60A5FA" stroke-width="2"/>- <rect x="82" y="60" width="68" height="8" rx="4" fill="#3B82F6"/>- <rect x="178" y="50" width="80" height="28" rx="8" fill="#F1F5F9"/>- <rect x="198" y="60" width="40" height="8" rx="4" fill="#CBD5E1"/>- <rect x="54" y="124" width="1092" height="92" rx="12" fill="#EFF6FF" stroke="#60A5FA" stroke-width="2"/>- <rect x="74" y="144" width="72" height="22" rx="6" fill="#BFDBFE"/>- <rect x="88" y="151" width="44" height="8" rx="4" fill="#3B82F6"/>- <rect x="74" y="182" width="640" height="10" rx="5" fill="#94A3B8"/>- <rect x="54" y="232" width="1092" height="116" rx="12" fill="#F8FAFC" stroke="#E2E8F0"/>- <rect x="74" y="252" width="96" height="22" rx="6" fill="#E2E8F0"/>- <rect x="88" y="259" width="60" height="8" rx="4" fill="#64748B"/>- <rect x="74" y="290" width="960" height="10" rx="5" fill="#CBD5E1"/>- <rect x="74" y="312" width="760" height="10" rx="5" fill="#CBD5E1"/>- <rect x="54" y="364" width="1092" height="120" rx="12" fill="#F0FDF4" stroke="#34D399" stroke-width="2"/>- <rect x="74" y="384" width="128" height="22" rx="6" fill="#A7F3D0"/>- <rect x="88" y="391" width="88" height="8" rx="4" fill="#059669"/>- <rect x="74" y="418" width="1052" height="48" rx="8" fill="#DCFCE7"/>- <rect x="90" y="432" width="220" height="8" rx="4" fill="#10B981"/>- <rect x="90" y="448" width="420" height="8" rx="4" fill="#6EE7B7"/>- <rect x="54" y="500" width="1092" height="140" rx="12" fill="#F5F3FF" stroke="#A78BFA" stroke-width="2"/>- <rect x="74" y="520" width="112" height="22" rx="6" fill="#DDD6FE"/>- <rect x="88" y="527" width="72" height="8" rx="4" fill="#7C3AED"/>- <rect x="74" y="558" width="1000" height="10" rx="5" fill="#C4B5FD"/>- <rect x="74" y="580" width="880" height="10" rx="5" fill="#C4B5FD"/>- <rect x="74" y="602" width="640" height="10" rx="5" fill="#DDD6FE"/>-</svg>diff --git a/web/src/features/feature-previews/components/ControlledFeaturePreviewModal.tsx b/web/src/features/feature-previews/components/ControlledFeaturePreviewModal.tsxindex 361f47ee60..94f57c5422 100644--- a/web/src/features/feature-previews/components/ControlledFeaturePreviewModal.tsx+++ b/web/src/features/feature-previews/components/ControlledFeaturePreviewModal.tsx@@ -81,19 +81,6 @@ export function ControlledFeaturePreviewModal({onToggle: onToggle("sessionTimeline"),isToggling: setFeaturePreviewEnabled.isPending,},- normalizedIoPreview: {- enabled:- authSession.data?.user?.featureFlags.normalizedIoPreview === true ||- authSession.data?.environment.enableExperimentalFeatures === true,- disabled:- authSession.data?.environment.enableExperimentalFeatures === true,- warningReason:- authSession.data?.environment.enableExperimentalFeatures === true- ? "This preview is enabled by LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES, so a per-user opt-out does not disable it."- : undefined,- onToggle: onToggle("normalizedIoPreview"),- isToggling: setFeaturePreviewEnabled.isPending,- },};return (diff --git a/web/src/features/feature-previews/components/FeaturePreviewModal.tsx b/web/src/features/feature-previews/components/FeaturePreviewModal.tsxindex ec4dbb0cd2..b18b6a67d4 100644--- a/web/src/features/feature-previews/components/FeaturePreviewModal.tsx+++ b/web/src/features/feature-previews/components/FeaturePreviewModal.tsx@@ -19,8 +19,6 @@ import {} from "@/src/features/feature-flags";import modernSessionDarkIllustration from "../assets/modern-session-dark.svg";import modernSessionLightIllustration from "../assets/modern-session-light.svg";-import improvedMessageRenderingDarkIllustration from "../assets/improved-message-rendering-dark.svg";-import improvedMessageRenderingLightIllustration from "../assets/improved-message-rendering-light.svg";/** Flags the Feature Preview modal can toggle. Keep in sync with the* userAccount.setFeaturePreviewEnabled allowlist and available-flags.ts. */@@ -68,19 +66,6 @@ const PREVIEW_REGISTRY: PreviewRegistryItem[] = [alt: "Compact Session View showing a trace minimap beside a continuous session conversation feed.",},},- {- flag: "normalizedIoPreview",- description:- "Render the Formatted view of trace and observation input/output more faithfully — chat messages, tool calls, and reasoning are recognized across a wide range of model providers and frameworks.",- details:- "A new parser understands the conventions of OpenAI, Anthropic, Gemini, LangChain, the Vercel AI SDK, OpenTelemetry GenAI, Pydantic AI, and more. Messages, tool calls, tool results, and reasoning render as structured blocks in the Formatted view instead of falling back to raw JSON. When enabled, the Formatted tab is powered by this parser everywhere trace and observation I/O is shown.",- feedbackUrl: "https://github.com/orgs/langfuse/discussions",- illustration: {- light: improvedMessageRenderingLightIllustration,- dark: improvedMessageRenderingDarkIllustration,- alt: "Formatted trace view rendering a user message, an assistant reply, a tool call, and a reasoning block as distinct structured cards.",- },- },];const FEATURE_PREVIEW_MODAL_TITLE = "Feature Preview";diff --git a/web/src/features/posthog-analytics/usePostHogClientCapture.ts b/web/src/features/posthog-analytics/usePostHogClientCapture.tsindex 33cc7abd4d..95ed526509 100644--- a/web/src/features/posthog-analytics/usePostHogClientCapture.ts+++ b/web/src/features/posthog-analytics/usePostHogClientCapture.ts@@ -27,7 +27,6 @@ const events = {"observation_tree_toggle_scores","observation_tree_toggle_metrics","io_mode_switch",- "io_parser_comparison","test_in_playground_button_click","display_mode_switch","download_button_click",diff --git a/web/src/features/sessions/SessionObservationIO.clienttest.tsx b/web/src/features/sessions/SessionObservationIO.clienttest.tsxindex 0a53405c3f..8be6fd218b 100644--- a/web/src/features/sessions/SessionObservationIO.clienttest.tsx+++ b/web/src/features/sessions/SessionObservationIO.clienttest.tsx@@ -71,9 +71,6 @@ const renderComponent = (onOpenInTraceView = vi.fn(),) => {render(- // IOPreview reads the normalizedIoPreview flag via useSession; a null- // session resolves it to false (legacy behavior), matching production- // for regular users.<SessionProvider session={null}><SessionObservationIOobservation={observation}diff --git a/web/src/features/traces/components/IOPreview/IOPreview.tsx b/web/src/features/traces/components/IOPreview/IOPreview.tsxindex 3f04ba0355..b9f3d489c0 100644--- a/web/src/features/traces/components/IOPreview/IOPreview.tsx+++ b/web/src/features/traces/components/IOPreview/IOPreview.tsx@@ -1,7 +1,6 @@/* eslint-disable no-nested-ternary */import { useEffect } from "react";import { type ScoreDomain, type Prisma } from "@langfuse/shared";-import { useIsFeatureEnabled } from "@/src/features/feature-flags";import { usePostHogClientCapture } from "@/src/features/posthog-analytics";import useLocalStorage from "@/src/components/useLocalStorage";import { usePreserveRelativeScroll } from "@/src/features/traces/hooks/usePreserveRelativeScroll";@@ -18,7 +17,6 @@ import { IOPreviewJSON, type IOPreviewJSONProps } from "./IOPreviewJSON";import { IOPreviewJSONSimple } from "./IOPreviewJSONSimple";import { IOPreviewPretty } from "./IOPreviewPretty";import { type ChatMLParserResult } from "../../hooks/useChatMLParser";-import type { IOPreviewParserComparisonOutcome } from "../../hooks/useIOPreviewParser";import { Button } from "@/src/components/ui/button";import { ActionButton } from "@/src/components/ActionButton";import { BookOpen, X } from "lucide-react";@@ -158,12 +156,6 @@ export function IOPreview({showCorrections = true,}: IOPreviewProps) {const capture = usePostHogClientCapture();- // "Improved Message Rendering" feature preview: when enabled, the Formatted- // view is powered by the normalized parser instead of the legacy one.- const improvedRenderingEnabled = useIsFeatureEnabled("normalizedIoPreview", {- enableForAdmins: false,- projectId,- });const [dismissedTraceViewNotifications, setDismissedTraceViewNotifications] =useLocalStorage<string[]>(STORAGE_KEY, []);@@ -314,17 +306,6 @@ export function IOPreview({) : (<IOPreviewPretty{...sharedProps}- parser={- // Precomputed legacy parses win inside the parser hook, so the- // Formatted view must never claim them as normalized output.- improvedRenderingEnabled && chatMLParserResult === undefined- ? "normalized"- : "legacy"- }- onParserComparison={(outcome: IOPreviewParserComparisonOutcome) =>- capture("trace_detail:io_parser_comparison", { outcome })- }- observationName={observationName}showMetadata={showMetadata}contentMode={contentMode}showSystemPrompt={showSystemPrompt}diff --git a/web/src/features/traces/components/IOPreview/IOPreviewPretty.tsx b/web/src/features/traces/components/IOPreview/IOPreviewPretty.tsxindex 63af5cf3d6..54c4e70af9 100644--- a/web/src/features/traces/components/IOPreview/IOPreviewPretty.tsx+++ b/web/src/features/traces/components/IOPreview/IOPreviewPretty.tsx@@ -1,5 +1,5 @@/* eslint-disable no-nested-ternary */-import { useEffect, useMemo, useRef } from "react";+import { useMemo } from "react";import { type Prisma, type ScoreDomain, deepParseJson } from "@langfuse/shared";import { PrettyJsonView } from "@/src/components/ui/PrettyJsonView";import { type MetadataFilterActions } from "@/src/components/table/ValueCell";@@ -7,8 +7,6 @@ import { useMarkdownRenderCharacterLimit } from "@/src/hooks/useMarkdownRenderChimport { type MediaReturnType } from "@/src/features/media";import { type ChatMLParserResult } from "../../hooks/useChatMLParser";import {- type IOPreviewParserComparisonOutcome,- type IOPreviewParserMode,hasRenderableChatMessages,useIOPreviewParser,} from "../../hooks/useIOPreviewParser";@@ -99,7 +97,6 @@ export interface IOPreviewPrettyProps extends ExpansionStateProps {parsedOutput?: unknown;parsedMetadata?: unknown;chatMLParserResult?: ChatMLParserResult;- observationName?: string;isLoading?: boolean;isParsing?: boolean;hideIfNull?: boolean;@@ -115,11 +112,6 @@ export interface IOPreviewPrettyProps extends ExpansionStateProps {showCorrections?: boolean;contentMode?: IOPreviewContentMode;showSystemPrompt?: boolean;- // Which parser produces the preview; the normalized parser is admin-only- // while it is being validated. Legacy remains the safe default.- parser?: IOPreviewParserMode;- // Called once after a normalized parser comparison has settled.- onParserComparison?: (outcome: IOPreviewParserComparisonOutcome) => void;}/**@@ -144,7 +136,6 @@ export function IOPreviewPretty({parsedOutput: preParsedOutput,parsedMetadata: preParsedMetadata,chatMLParserResult,- observationName,isLoading = false,isParsing = false,hideIfNull = false,@@ -165,8 +156,6 @@ export function IOPreviewPretty({showCorrections = true,contentMode = "all",showSystemPrompt,- parser = "legacy",- onParserComparison,}: IOPreviewPrettyProps) {// Use pre-parsed data if available (from useParsedObservation hook),// otherwise parse with size/depth limits to prevent UI freeze@@ -194,14 +183,11 @@ export function IOPreviewPretty({[projectId, observationId],);- // Parse into the shared preview contract. The normalized parser is opt-in- // while it is being rolled out; legacy remains the safe default.- const { result: parserResult, comparisonOutcome } = useIOPreviewParser(- parser,+ // Parse into the shared preview contract.+ const parserResult = useIOPreviewParser(input,output,metadata,- observationName,parsedInput,parsedOutput,parsedMetadata,@@ -219,33 +205,6 @@ export function IOPreviewPretty({inputMessageCount,} = parserResult;- const capturedComparisonRecord = useRef<string | undefined>(undefined);- useEffect(() => {- if (- parser !== "normalized" ||- comparisonOutcome === undefined ||- !onParserComparison ||- isLoading ||- isParsing- ) {- return;- }-- const recordKey = `${observationId ? "observation" : "trace"}:${observationId ?? traceId}`;- if (capturedComparisonRecord.current === recordKey) return;-- capturedComparisonRecord.current = recordKey;- onParserComparison(comparisonOutcome);- }, [- comparisonOutcome,- isLoading,- isParsing,- observationId,- onParserComparison,- parser,- traceId,- ]);-const characterLimit = useMarkdownRenderCharacterLimit();// Determine if markdown is safe to render (content size check)diff --git a/web/src/features/traces/hooks/useIOPreviewParser.clienttest.ts b/web/src/features/traces/hooks/useIOPreviewParser.clienttest.tsdeleted file mode 100644index 8b41d32858..0000000000--- a/web/src/features/traces/hooks/useIOPreviewParser.clienttest.ts+++ /dev/null@@ -1,66 +0,0 @@-import { describe, expect, it } from "vitest";-import type { ChatMLParserResult, ChatMlMessage } from "./useChatMLParser";-import {- hasRenderableChatMessages,- selectIOPreviewParserResult,-} from "./useIOPreviewParser";--const createMessage = (fields: Partial<ChatMlMessage>): ChatMlMessage =>- fields as ChatMlMessage;--const result = (- overrides: Partial<ChatMLParserResult> = {},-): ChatMLParserResult => ({- canDisplayAsChat: true,- allMessages: [createMessage({ role: "user", content: "hello" })],- additionalInput: undefined,- allTools: [],- toolCallCounts: new Map(),- toolCallsByName: new Map(),- messageToToolCallNumbers: new Map(),- toolNameToDefinitionNumber: new Map(),- inputMessageCount: 1,- ...overrides,-});--describe("IO preview parser comparison", () => {- it.each([- ["both", result(), result()],- ["normalized_only", result(), result({ canDisplayAsChat: false })],- ["legacy_only", result({ canDisplayAsChat: false }), result()],- [- "neither",- result({ canDisplayAsChat: false }),- result({ canDisplayAsChat: false }),- ],- ] as const)("reports %s", (outcome, normalized, legacy) => {- expect(- selectIOPreviewParserResult(normalized, legacy).comparisonOutcome,- ).toBe(outcome);- });-- it("treats a JSON-only message as not renderable chat", () => {- expect(- hasRenderableChatMessages(- result({- allMessages: [- createMessage({- role: "user",- json: { raw: "value" },- }),- ],- }),- ),- ).toBe(false);- });-- it("falls back to legacy when normalized has no renderable messages", () => {- const normalized = result({ canDisplayAsChat: false });- const legacy = result();-- expect(selectIOPreviewParserResult(normalized, legacy)).toEqual({- result: legacy,- comparisonOutcome: "legacy_only",- });- });-});diff --git a/web/src/features/traces/hooks/useIOPreviewParser.ts b/web/src/features/traces/hooks/useIOPreviewParser.tsindex c9f77d5d6f..696244f16e 100644--- a/web/src/features/traces/hooks/useIOPreviewParser.ts+++ b/web/src/features/traces/hooks/useIOPreviewParser.ts@@ -2,22 +2,11 @@import { useMemo } from "react";import { type Prisma, deepParseJson } from "@langfuse/shared";import { normalizeSpanIO } from "@langfuse/shared/src/utils/normalized-io";+import { reportError } from "@/src/utils/reportError";import { toIOPreview } from "../parsers/toIOPreview";-import { parseChatML, type ChatMLParserResult } from "./useChatMLParser";+import { type ChatMLParserResult } from "./useChatMLParser";import { isOnlyJsonMessage } from "../fns/chatMessageUtils";-export type IOPreviewParserMode = "legacy" | "normalized";-export type IOPreviewParserComparisonOutcome =- | "both"- | "normalized_only"- | "legacy_only"- | "neither";--export interface IOPreviewParserResult {- result: ChatMLParserResult;- comparisonOutcome?: IOPreviewParserComparisonOutcome;-}-/** The same message-level displayability check used by the pretty preview. */export function hasRenderableChatMessages(result: ChatMLParserResult): boolean {return (@@ -25,63 +14,24 @@ export function hasRenderableChatMessages(result: ChatMLParserResult): boolean {);}-export function selectIOPreviewParserResult(- normalizedResult: ChatMLParserResult | undefined,- legacyResult: ChatMLParserResult,-): IOPreviewParserResult {- const normalizedWorks =- normalizedResult !== undefined &&- hasRenderableChatMessages(normalizedResult);- const legacyWorks = hasRenderableChatMessages(legacyResult);-- if (normalizedWorks && legacyWorks) {- return {- result: normalizedResult,- comparisonOutcome: "both",- };- }-- if (normalizedWorks) {- return {- result: normalizedResult,- comparisonOutcome: "normalized_only",- };- }-- if (legacyWorks) {- return {- result: legacyResult,- comparisonOutcome: "legacy_only",- };- }-- return {- // Keep normalized data when available so tool definitions and other- // extracted details remain visible while the UI falls back to JSON.- result: normalizedResult ?? legacyResult,- comparisonOutcome: "neither",- };-}-/**- * Selects the parser used by the pretty I/O preview.+ * Parses observation I/O into the contract rendered by the Formatted view.*- * Both parsers return the same ChatMLParserResult, so the rendering tree does- * not need to know which representation produced it. A normalized parse is- * deliberately best-effort: malformed or unsupported data falls back to the- * established parser for this observation.+ * A precomputed result wins so surfaces that already parsed (the session+ * feed) are not parsed twice. Parsing is best-effort: a payload the parser+ * cannot handle yields no chat messages and the view falls back to JSON. The+ * parser is not expected to throw; if it does, that is a parser bug worth a+ * Sentry issue, and the view still falls back to JSON.*/export function useIOPreviewParser(- parser: IOPreviewParserMode,input: Prisma.JsonValue | undefined,output: Prisma.JsonValue | undefined,metadata: Prisma.JsonValue | undefined,- observationName: string | undefined,preParsedInput?: unknown,preParsedOutput?: unknown,preParsedMetadata?: unknown,preParsedResult?: ChatMLParserResult,-): IOPreviewParserResult {+): ChatMLParserResult {const parsedInput = preParsedResult? undefined: preParsedInput !== undefined@@ -98,37 +48,19 @@ export function useIOPreviewParser(? preParsedMetadata: deepParseJson(metadata, { maxSize: 100_000, maxDepth: 25 });- return useMemo<IOPreviewParserResult>(() => {- // Precomputed results win regardless of parser mode; surfaces that supply- // one disable the normalized-beta tab (see IOPreview) so labels stay honest.- if (preParsedResult) return { result: preParsedResult };-- const parseLegacy = () =>- parseChatML(parsedInput, parsedOutput, parsedMetadata, observationName);+ return useMemo<ChatMLParserResult>(() => {+ if (preParsedResult) return preParsedResult;- if (parser === "legacy") return { result: parseLegacy() };-- let normalizedResult: ChatMLParserResult | undefined;+ const span = {+ input: parsedInput,+ output: parsedOutput,+ metadata: parsedMetadata,+ };try {- const normalized = normalizeSpanIO({- input: parsedInput,- output: parsedOutput,- metadata: parsedMetadata,- });- normalizedResult = toIOPreview(normalized);- } catch {- // The legacy parser remains the visible fallback for malformed input.+ return toIOPreview(normalizeSpanIO(span));+ } catch (error) {+ reportError(error, { area: "io-preview-parser" });+ return toIOPreview({ messages: [], toolDefinitions: [], span });}-- const legacyResult = parseLegacy();-- return selectIOPreviewParserResult(normalizedResult, legacyResult);- }, [- parser,- preParsedResult,- parsedInput,- parsedOutput,- parsedMetadata,- observationName,- ]);+ }, [preParsedResult, parsedInput, parsedOutput, parsedMetadata]);}