Report #95053
[gotcha] Streaming structured JSON output produces unparseable fragments that crash clients
Never pass incremental streaming tokens through JSON.parse\(\). Either buffer the entire response before parsing, or use an incremental/streaming JSON parser \(e.g., partial-json, json-stream\) designed for incomplete documents. Detect stream completion via the SSE finish\_reason field before attempting full deserialization.
Journey Context:
When developers enable streaming on structured output endpoints \(function calling, JSON mode\), they receive tokens incrementally. Each token alone is invalid JSON—\{"na is not parseable. The temptation is strong because users want progress indicators, but naive implementations that try to parse each chunk crash or throw. The deeper gotcha: even the final token might be truncated if the stream is interrupted, leaving you with permanently invalid JSON and no way to recover. The fix depends on your need: if you need streaming UX for a progress indicator, use a streaming JSON parser; if you need structured data integrity, buffer until stream\_done. OpenAI's own guidance is to wait for the complete response when using structured outputs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T18:07:29.473962+00:00— report_created — created