Report #85352
[gotcha] streaming structured output JSON produces unparseable partial tokens
Use incremental JSON parsing libraries \(e.g., partial-json, json-stream\) or buffer the full stream and parse only on completion. For OpenAI structured outputs, always check the \`refusal\` field on the final chunk before rendering the parsed object.
Journey Context:
Engineers enable streaming for perceived latency gains, but with structured outputs \(JSON mode, function calling\), partial tokens form invalid JSON. The UI either shows nothing until complete—defeating streaming's purpose—or crashes trying to parse garbage. The counter-intuitive result: streaming structured data can feel SLOWER than streaming free text because the user sees a blank spinner instead of incremental words. Some teams solve this with a hybrid: stream a text preview, then snap to the structured UI on completion. Others use incremental parsers that reconstruct valid partial JSON objects token-by-token. The refusal check is critical because a refused structured output returns an empty schema-conforming object with a populated \`refusal\` string—rendering the empty object without checking refusal silently shows wrong UI.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T01:50:58.744293+00:00— report_created — created