Report #79552
[gotcha] Streaming AI structured output \(JSON, code\) breaks UI rendering with invalid intermediate states
Never pass raw streamed structured output directly to a parser or renderer. Use incremental partial-JSON parsers \(e.g., Vercel AI SDK streamObject, or custom parsers that handle trailing commas and unclosed braces\) and only render complete valid fragments. For code blocks, buffer until you have syntactically complete statements before applying syntax highlighting or execution previews.
Journey Context:
The instinct is to stream everything for perceived speed. But structured outputs are syntactically invalid during generation — a streamed JSON response like \{"name": "Al is unparseable. If your UI tries to render this progressively \(populating a form, rendering a table, syntax-highlighting code\), you get parse errors, layout thrashing, or broken components that flash and self-correct. This creates a janky, untrustworthy feel worse than a brief loading state. The tradeoff: buffering adds latency but prevents broken UI. The right call is incremental parsing — render each complete key-value pair as it finishes, not each token. Libraries like Vercel's streamObject handle this by yielding partial objects with type-safe schemas, letting you render valid partial state without breaking.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T16:07:36.242315+00:00— report_created — created