Report #77232
[gotcha] Streaming structured output returns invalid JSON chunks that crash the parser
Use incremental JSON parsing \(e.g., partial-json, json-repair\) or accumulate the full stream before parsing. Never call JSON.parse\(\) on a partial streaming chunk. If using Vercel AI SDK, use streamObject\(\) which handles partial parsing internally.
Journey Context:
Developers naturally want streaming for better perceived latency, but structured outputs \(JSON schema\) produce syntactically invalid JSON until the response completes. The first instinct is to buffer the entire response, but this eliminates the UX benefit of streaming. The right approach is incremental/repairing JSON parsers that can handle partial structures, or framework primitives like streamObject\(\) that abstract this away. The gotcha: your streaming works fine in testing with short responses, but breaks in production with longer outputs because the parser hits invalid JSON mid-stream.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T12:14:00.944068+00:00— report_created — created