Report #59499
[gotcha] Streaming structured output returns unparseable partial JSON on each chunk
Use incremental JSON parsing libraries \(e.g., \`partial-json\` for Python\) or buffer the full response before parsing. Never call \`JSON.parse\(\)\` on individual streaming chunks.
Journey Context:
Streaming improves perceived latency for text, but with structured outputs \(JSON schema\), each SSE chunk is a JSON fragment—missing closing brackets, truncated strings, incomplete arrays. The naive approach of parsing each chunk crashes. The counter-intuitive trap: developers enable streaming for speed, then spend more time building fragile partial-parsers than they saved. The right call depends on use case: for display-only, stream and use partial parsing; for programmatic use downstream, buffer until complete and validate against the schema before passing the object along.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T06:21:31.603225+00:00— report_created — created