Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(llma): bound long string render cost in JSON viewer (#61328)

posthog[bot]b590709f6581
diff --git a/frontend/src/lib/components/JSONViewer.tsx b/frontend/src/lib/components/JSONViewer.tsx
index ec160a797670..3b8d8cc8e2bd 100644
--- a/frontend/src/lib/components/JSONViewer.tsx
+++ b/frontend/src/lib/components/JSONViewer.tsx
@@ -19,6 +19,10 @@ export function JSONViewerInner({
name = null, // Don't label the root node as "root" by default
displayDataTypes = false, // Reduce visual clutter
displayObjectSize = false, // Reduce visual clutter
+ // Truncate very long strings by default — they stay one click away from full expansion. Without
+ // this, pathologically long values (LLM prompts/completions, tool args, base64 image blobs in
+ // AI traces) render inline in full, which thrashes layout and makes expand/collapse clicks lag.
+ collapseStringsAfterLength = 10000,
...props
}: ReactJsonViewProps): JSX.Element {
const { isDarkModeOn } = useValues(themeLogic)
@@ -33,6 +37,7 @@ export function JSONViewerInner({
name={name}
displayDataTypes={displayDataTypes}
displayObjectSize={displayObjectSize}
+ collapseStringsAfterLength={collapseStringsAfterLength}
enableClipboard={(copy) => {
// The library wraps string values in quotes.
// Re-copy with raw string value so users get the actual content.
diff --git a/products/ai_observability/frontend/components/JSONValueDisplay.test.tsx b/products/ai_observability/frontend/components/JSONValueDisplay.test.tsx
index 11658e3b34db..c0fd5b10cdf5 100644
--- a/products/ai_observability/frontend/components/JSONValueDisplay.test.tsx
+++ b/products/ai_observability/frontend/components/JSONValueDisplay.test.tsx
@@ -60,4 +60,17 @@ describe('JSONValueDisplay', () => {
expect(container.querySelector('.react-json-view')).not.toBeInTheDocument()
expect(container.textContent).toContain('[Thinking: not JSON]')
})
+
+ it('truncates pathologically long string values by default', async () => {
+ // Guards against huge inline values (LLM prompts/completions, base64 blobs) thrashing render.
+ const hugeValue = 'X'.repeat(20000)
+ const { container } = renderValue({ prompt: hugeValue })
+
+ await waitFor(() => {
+ expect(container.querySelector('.react-json-view')).toBeInTheDocument()
+ })
+ // The full string is not rendered, but a truncated prefix still is (expandable on click).
+ expect(container.textContent).not.toContain('X'.repeat(20000))
+ expect(container.textContent).toContain('X'.repeat(10000))
+ })
})