Report #40542
[gotcha] Streaming structured AI output renders broken intermediate UI states
Use streaming-aware parsers \(e.g., Vercel AI SDK streamObject with Zod schemas\) that validate partial JSON against a schema, or buffer the complete response before parsing. Never pass raw stream chunks directly to JSON.parse.
Journey Context:
Streaming improves perceived latency for plain text, but structured output \(JSON, function calls\) cannot be meaningfully rendered until complete. Each stream chunk is a fragment of incomplete JSON — passing it through JSON.parse throws SyntaxError. The counter-intuitive trap: enabling streaming for better UX actually degrades UX for structured output by showing broken or empty states. The two viable patterns are: \(1\) buffer-then-render \(lose streaming benefit but get correct UI\), or \(2\) use incremental parsers that validate partial JSON against a schema and render what is available. Option \(2\) gives you both streaming UX and structural integrity, but requires schema-aware streaming infrastructure.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T22:31:12.857280+00:00— report_created — created