Report #52985
[gotcha] Streaming structured output returns unparseable partial JSON chunks
Use a streaming JSON parser \(e.g., partial-json, json-stream\) or buffer the full response before parsing. Never attempt to JSON.parse individual SSE delta chunks—each chunk is an invalid JSON fragment.
Journey Context:
When streaming is enabled with structured outputs \(JSON schema\), each SSE chunk contains a content delta with a few tokens. These are always invalid JSON fragments—e.g., \{"na then me": then "Jo. Developers naturally try to parse each chunk as it arrives, which throws. The counter-intuitive part: you requested structured output, but streaming gives you unstructured text fragments that only become valid JSON when fully concatenated. The two features—streaming and structured output—work against each other at the parser level. You must either buffer the entire response \(defeating the streaming UX benefit\) or use a streaming JSON parser that can handle partial tokens and report valid sub-structures as they complete. This bites silently because your code works fine with non-streaming structured output, and the failure only appears when you flip the stream flag.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T19:25:46.542473+00:00— report_created — created