Skip to content

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

fix(trace-ui): don't render markdown if content too big (#9190)

Nimard7069df433ba
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index d8e7ce5a38..a4e5963e61 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -55,7 +55,7 @@ importers:
version: 7.0.6
next:
specifier: 15.5.2
next-auth:
specifier: ^4.24.11
@@ -392,7 +392,7 @@ importers:
'@next-auth/prisma-adapter':
specifier: ^1.0.7
'@opentelemetry/api':
specifier: ^1.9.0
version: 1.9.0
@@ -515,7 +515,7 @@ importers:
version: 4.2.0([email protected])
'@sentry/nextjs':
specifier: ^10.11.0
'@t3-oss/env-nextjs':
specifier: ^0.11.1
@@ -539,7 +539,7 @@ importers:
'@trpc/next':
specifier: ^11.4.4
'@trpc/react-query':
specifier: ^11.4.4
@@ -626,19 +626,19 @@ importers:
version: 3.3.11
next:
specifier: 15.5.2
next-auth:
specifier: ^4.24.11
next-query-params:
specifier: ^5.1.0
next-themes:
specifier: ^0.4.6
posthog-js:
- specifier: ^1.176.0
- version: 1.176.0
+ specifier: ^1.266.0
+ version: 1.266.0
posthog-node:
specifier: ^5.8.4
version: 5.8.4
@@ -10650,8 +10650,16 @@ packages:
resolution: {integrity: sha512-i/hbxIE9803Alj/6ytL7UHQxRvZkI9O4Sy+J3HGc4F4oo/2eQAjTSNJ0bfxyse3bH0nuVesCk+3IRLaMtG3H6w==}
- resolution: {integrity: sha512-T5XKNtRzp7q6CGb7Vc7wAI76rWap9fiuDUPxPsyPBPDkreKya91x9RIsSapAVFafwD1AEin1QMczCmt9Le9BWw==}
+ resolution: {integrity: sha512-437KsO9N+pMW6FtilgKYTHel0RCWs2S7PvsNRJf20/f3npChX9i6F8cNCJ6O4Az37scC1kPdTknFY/xEGazVJw==}
+ peerDependencies:
+ '@rrweb/types': 2.0.0-alpha.17
+ rrweb-snapshot: 2.0.0-alpha.17
+ peerDependenciesMeta:
+ '@rrweb/types':
+ optional: true
+ rrweb-snapshot:
+ optional: true
resolution: {integrity: sha512-O0lObQqeIiggNCjc5BQx5PaHqPzXxwKnCJdb+DuNkbDO6Vc442SQ5FDv0WjPd5Ejfwme1uGZmM5/xhHWKegFfQ==}
@@ -10668,6 +10676,9 @@ packages:
resolution: {integrity: sha512-IJOW6cQN1fwfC17HfNOqUtAGyB8wAYshuC+jG1JiL/1+sC4yVyuA3IcF0N9vdodMJjW/lbuEF5qFsJqGNcbHbw==}
+ resolution: {integrity: sha512-5SYSgFKSyhCbk6SrXyMpqjb5+MQBgfvEKE/OC+PujcY34sOpqtr+0AZQtPYx5IA6VxynQ7rUPCtKzyovpj9Bpg==}
+
resolution: {integrity: sha512-QCYG84SgGyGzqJ/vlMsxeXd/pgL/I94ixdNFyh1PusWmTCyVfPJjZ1K1jvHtsbfnXQs2TSkEP2fR7QiMZAnKFQ==}
engines: {node: '>= 0.6'}
@@ -12526,8 +12537,8 @@ packages:
resolution: {integrity: sha512-QW95TCTaHmsYfHDybGMwO5IJIM93I/6vTRk+daHTWFPhwh+C8Cg7j7XyKrwrj8Ib6vYXe0ocYNrmzY4xAAN6ug==}
engines: {node: '>= 14'}
- resolution: {integrity: sha512-/CFAm1mNxSmOj6i0Co+iGFJ58OS4NRGVP+AWS/l509uIK5a1bSoIVaHz/ZumpHTfHSZBpgrJ+wjfpAOrTHok5Q==}
+ resolution: {integrity: sha512-r4DIlprAGwJ7YM11VZp4R884m0Vmgr6EAKe3P+kO0PPj3Unqyvv59rczf6UiGcb9Z8QxZVcqKNwv/g0WNdWwsw==}
resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}
@@ -12912,13 +12923,13 @@ snapshots:
'@aws-sdk/types': 3.821.0
'@aws-sdk/util-locate-window': 3.568.0
'@smithy/util-utf8': 2.3.0
- tslib: 2.6.3
+ tslib: 2.8.1
'@aws-crypto/[email protected]':
dependencies:
'@aws-crypto/util': 5.2.0
'@aws-sdk/types': 3.821.0
- tslib: 2.6.3
+ tslib: 2.8.1
'@aws-crypto/[email protected]':
dependencies:
@@ -15702,10 +15713,10 @@ snapshots:
transitivePeerDependencies:
- '@types/react'
dependencies:
dependencies:
@@ -17625,7 +17636,7 @@ snapshots:
'@sentry/[email protected]': {}
dependencies:
'@opentelemetry/api': 1.9.0
'@opentelemetry/semantic-conventions': 1.37.0
@@ -17639,7 +17650,7 @@ snapshots:
'@sentry/vercel-edge': 10.11.0
'@sentry/webpack-plugin': 4.3.0([email protected])
chalk: 3.0.0
resolve: 1.22.8
rollup: 4.50.2
stacktrace-parser: 0.1.11
@@ -18515,7 +18526,7 @@ snapshots:
'@jest/globals': 29.7.0
'@types/jest': 29.5.12
+ vitest: 3.2.4(@types/[email protected])
dependencies:
@@ -18550,11 +18561,11 @@ snapshots:
'@trpc/server': 11.4.4([email protected])
typescript: 5.9.2
dependencies:
'@trpc/server': 11.4.4([email protected])
react: 19.1.1
react-dom: 19.1.1([email protected])
typescript: 5.9.2
@@ -19231,6 +19242,15 @@ snapshots:
+ dependencies:
+ '@vitest/spy': 3.2.4
+ estree-walker: 3.0.3
+ magic-string: 0.30.19
+ optionalDependencies:
+ vite: 7.0.5(@types/[email protected])
+ optional: true
+
'@vitest/[email protected]':
dependencies:
tinyrainbow: 2.0.0
@@ -19244,7 +19264,7 @@ snapshots:
'@vitest/[email protected]':
dependencies:
'@vitest/pretty-format': 3.2.4
- magic-string: 0.30.17
+ magic-string: 0.30.19
pathe: 2.0.3
'@vitest/[email protected]':
@@ -21894,7 +21914,7 @@ snapshots:
dependencies:
- debug: 4.3.4
+ debug: 4.4.3
get-stream: 5.2.0
yauzl: 2.10.0
optionalDependencies:
@@ -21948,7 +21968,7 @@ snapshots:
dependencies:
- strnum: 1.0.5
+ strnum: 1.1.2
dependencies:
@@ -24492,13 +24512,30 @@ snapshots:
dependencies:
type-fest: 2.19.0
+ dependencies:
+ '@babel/runtime': 7.26.0
+ '@panva/hkdf': 1.1.1
+ cookie: 0.7.2
+ jose: 4.15.5
+ oauth: 0.9.15
+ openid-client: 5.6.5
+ preact: 10.19.7
+ preact-render-to-string: 5.2.6([email protected])
+ react: 19.1.1
+ react-dom: 19.1.1([email protected])
+ uuid: 8.3.2
+ optionalDependencies:
+ nodemailer: 6.9.15
+
dependencies:
'@babel/runtime': 7.26.0
'@panva/hkdf': 1.1.1
cookie: 0.7.2
jose: 4.15.5
oauth: 0.9.15
openid-client: 5.6.5
preact: 10.19.7
@@ -24509,9 +24546,9 @@ snapshots:
optionalDependencies:
nodemailer: 6.9.15
dependencies:
react: 19.1.1
tslib: 2.8.1
@@ -24521,7 +24558,7 @@ snapshots:
react: 19.1.1
react-dom: 19.1.1([email protected])
dependencies:
'@next/env': 15.5.2
'@swc/helpers': 0.5.15
@@ -24529,7 +24566,7 @@ snapshots:
postcss: 8.4.31
react: 19.1.1
react-dom: 19.1.1([email protected])
optionalDependencies:
'@next/swc-darwin-arm64': 15.5.2
'@next/swc-darwin-x64': 15.5.2
@@ -25177,12 +25214,13 @@ snapshots:
dependencies:
+ '@posthog/core': 1.0.2
core-js: 3.38.1
fflate: 0.4.8
- preact: 10.19.7
- web-vitals: 4.2.3
+ preact: 10.27.2
+ web-vitals: 4.2.4
dependencies:
@@ -25197,6 +25235,8 @@ snapshots:
+
@@ -26484,12 +26524,12 @@ snapshots:
dependencies:
inline-style-parser: 0.2.4
dependencies:
client-only: 0.0.1
react: 19.1.1
optionalDependencies:
- '@babel/core': 7.24.3
+ '@babel/core': 7.28.4
babel-plugin-macros: 3.1.0
@@ -27201,6 +27241,28 @@ snapshots:
'@egjs/hammerjs': 2.0.17
component-emitter: 1.3.1
+ dependencies:
+ cac: 6.7.14
+ debug: 4.4.3
+ es-module-lexer: 1.7.0
+ pathe: 2.0.3
+ vite: 7.0.5(@types/[email protected])
+ transitivePeerDependencies:
+ - '@types/node'
+ - jiti
+ - less
+ - lightningcss
+ - sass
+ - sass-embedded
+ - stylus
+ - sugarss
+ - supports-color
+ - terser
+ - tsx
+ - yaml
+ optional: true
+
dependencies:
cac: 6.7.14
@@ -27222,6 +27284,19 @@ snapshots:
- tsx
- yaml
+ dependencies:
+ esbuild: 0.25.7
+ fdir: 6.5.0([email protected])
+ picomatch: 4.0.3
+ postcss: 8.5.6
+ rollup: 4.50.2
+ tinyglobby: 0.2.14
+ optionalDependencies:
+ '@types/node': 24.3.0
+ fsevents: 2.3.3
+ optional: true
+
dependencies:
esbuild: 0.25.7
@@ -27281,6 +27356,48 @@ snapshots:
- tsx
- yaml
+ dependencies:
+ '@types/chai': 5.2.2
+ '@vitest/expect': 3.2.4
+ '@vitest/mocker': 3.2.4([email protected](@types/[email protected]))
+ '@vitest/pretty-format': 3.2.4
+ '@vitest/runner': 3.2.4
+ '@vitest/snapshot': 3.2.4
+ '@vitest/spy': 3.2.4
+ '@vitest/utils': 3.2.4
+ chai: 5.2.1
+ debug: 4.4.3
+ expect-type: 1.2.2
+ magic-string: 0.30.19
+ pathe: 2.0.3
+ picomatch: 4.0.3
+ std-env: 3.9.0
+ tinybench: 2.9.0
+ tinyexec: 0.3.2
+ tinyglobby: 0.2.14
+ tinypool: 1.1.1
+ tinyrainbow: 2.0.0
+ vite: 7.0.5(@types/[email protected])
+ vite-node: 3.2.4(@types/[email protected])
+ why-is-node-running: 2.3.0
+ optionalDependencies:
+ '@types/node': 24.3.0
+ transitivePeerDependencies:
+ - jiti
+ - less
+ - lightningcss
+ - msw
+ - sass
+ - sass-embedded
+ - stylus
+ - sugarss
+ - supports-color
+ - terser
+ - tsx
+ - yaml
+ optional: true
+
@@ -27327,7 +27444,7 @@ snapshots:
diff --git a/web/package.json b/web/package.json
index b9b1453ff5..8cc0ee8b5c 100644
--- a/web/package.json
+++ b/web/package.json
@@ -125,7 +125,7 @@
"next-auth": "^4.24.11",
"next-query-params": "^5.1.0",
"next-themes": "^0.4.6",
- "posthog-js": "^1.176.0",
+ "posthog-js": "^1.266.0",
"posthog-node": "^5.8.4",
"prexit": "^2.2.0",
"prism-react-renderer": "^2.4.1",
diff --git a/web/src/components/trace/IOPreview.tsx b/web/src/components/trace/IOPreview.tsx
index 90aadcb9f3..208bc6ddd4 100644
--- a/web/src/components/trace/IOPreview.tsx
+++ b/web/src/components/trace/IOPreview.tsx
@@ -17,6 +17,7 @@ import { Tabs, TabsList, TabsTrigger } from "@/src/components/ui/tabs";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
import useLocalStorage from "@/src/components/useLocalStorage";
import usePreserveRelativeScroll from "@/src/hooks/usePreserveRelativeScroll";
+import { MARKDOWN_RENDER_CHARACTER_LIMIT } from "@/src/utils/constants";
export const IOPreview: React.FC<{
input?: Prisma.JsonValue;
@@ -115,6 +116,17 @@ export const IOPreview: React.FC<{
)
: undefined;
+ // Don't render markdown if total content size exceeds limit
+ const inputSize = JSON.stringify(input || {}).length;
+ const outputSize = JSON.stringify(outputClean || {}).length;
+ const messagesSize = inChatMlArray.success
+ ? JSON.stringify(inChatMlArray.data).length
+ : 0;
+ const totalContentSize = inputSize + outputSize + messagesSize;
+
+ const shouldRenderMarkdownSafely =
+ totalContentSize <= MARKDOWN_RENDER_CHARACTER_LIMIT;
+
// default I/O
return (
<>
@@ -166,7 +178,7 @@ export const IOPreview: React.FC<{
} as ChatMlMessageSchema,
]),
]}
- shouldRenderMarkdown
+ shouldRenderMarkdown={shouldRenderMarkdownSafely}
additionalInput={
Object.keys(additionalInput ?? {}).length > 0
? additionalInput
diff --git a/web/src/components/ui/MarkdownJsonView.tsx b/web/src/components/ui/MarkdownJsonView.tsx
index daa71ec282..966c959a31 100644
--- a/web/src/components/ui/MarkdownJsonView.tsx
+++ b/web/src/components/ui/MarkdownJsonView.tsx
@@ -10,6 +10,7 @@ import { type MediaReturnType } from "@/src/features/media/validation";
import { Check, Copy } from "lucide-react";
import { useMemo, useState } from "react";
import { type z } from "zod/v4";
+import { MARKDOWN_RENDER_CHARACTER_LIMIT } from "@/src/utils/constants";
type MarkdownJsonViewHeaderProps = {
title: string;
@@ -59,7 +60,17 @@ export function MarkdownJsonViewHeader({
const isSupportedMarkdownFormat = (
content: unknown,
contentValidation: z.ZodSafeParseResult<z.infer<typeof OpenAIContentSchema>>,
-): content is z.infer<typeof OpenAIContentSchema> => contentValidation.success;
+): content is z.infer<typeof OpenAIContentSchema> => {
+ if (!contentValidation.success) return false;
+
+ // Don't render if markdown content is huge
+ const contentSize = JSON.stringify(content || {}).length;
+ if (contentSize > MARKDOWN_RENDER_CHARACTER_LIMIT) {
+ return false;
+ }
+
+ return true;
+};
// MarkdownJsonView will render markdown if `isMarkdownEnabled` (global context) is true and the content is valid markdown
// otherwise, if content is valid markdown will render JSON with switch to enable markdown globally
diff --git a/web/src/components/ui/PrettyJsonView.tsx b/web/src/components/ui/PrettyJsonView.tsx
index c134261b36..3484dd90a3 100644
--- a/web/src/components/ui/PrettyJsonView.tsx
+++ b/web/src/components/ui/PrettyJsonView.tsx
@@ -40,6 +40,7 @@ import {
StringOrMarkdownSchema,
containsAnyMarkdown,
} from "@/src/components/schemas/MarkdownSchema";
+import { MARKDOWN_RENDER_CHARACTER_LIMIT } from "@/src/utils/constants";
import {
convertRowIdToKeyPath,
getRowChildren,
@@ -136,6 +137,11 @@ function isMarkdownContent(json: unknown): {
isMarkdown: boolean;
content?: string;
} {
+ const contentSize = JSON.stringify(json || {}).length;
+ if (contentSize > MARKDOWN_RENDER_CHARACTER_LIMIT) {
+ return { isMarkdown: false };
+ }
+
if (typeof json === "string") {
const markdownResult = StringOrMarkdownSchema.safeParse(json);
if (markdownResult.success) {
diff --git a/web/src/utils/constants.ts b/web/src/utils/constants.ts
new file mode 100644
index 0000000000..f5a6260bb2
--- /dev/null
+++ b/web/src/utils/constants.ts
@@ -0,0 +1,3 @@
+// Don't render markdown in the frontend if the content exceeds the character count
+// react-markdown is unfortunately too slow to bear this for now.
+export const MARKDOWN_RENDER_CHARACTER_LIMIT = 150000;