Report #47307
[gotcha] Streaming structured output returns partial JSON fragments that break naive parsing
Use a partial or incremental JSON parser designed for streaming \(e.g. Vercel AI SDK streamObject, or libraries like partial-json\) that can construct valid objects from fragments. Alternatively, buffer the full response before parsing. Never attempt JSON.parse\(\) on individual streaming content chunks when using JSON mode or structured output.
Journey Context:
When using structured output features \(JSON mode, response\_format with json\_schema\), the streaming content chunks contain fragments of a JSON object that are syntactically invalid on their own. A chunk might be '\{"name": "Al' and the next 'ice", "age": 3' — neither is valid JSON. Developers who successfully stream plain text content try the same concatenation-and-parse pattern with structured output and hit parse errors on every chunk. This is distinct from the tool call argument streaming problem: here the entire response body is structured JSON, not just the arguments field. The solution requires either a partial JSON parser that can progressively build a valid object from fragments \(allowing progressive UI updates as fields populate\) or buffering the entire response before parsing \(simpler but loses the streaming UX benefit\). The Vercel AI SDK provides streamObject specifically for this pattern.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:53:37.536165+00:00— report_created — created