Report #83429
[gotcha] Streaming breaks when switching from text responses to structured JSON output
Use incremental JSON parsers \(e.g., partial-json, json-stream\) to render partial structured output into progressive UI states, or buffer the full response before parsing. Never append streamed JSON deltas directly to a text renderer expecting valid JSON at every frame.
Journey Context:
Text streaming works because any string prefix is valid text. JSON streaming fails because \`\{"key": "val\` is invalid and unparseable. Developers build a working streaming UX with text, then add structured output \(function calling, JSON mode, structured outputs\) and their renderer crashes on partial JSON. OpenAI's structured outputs API returns content deltas that must be accumulated and incrementally parsed — you cannot just concatenate them as text. The counter-intuitive part: streaming IS supported for structured outputs, but requires a fundamentally different rendering architecture where you parse partial JSON into partial UI states, not just append text to a buffer. Many teams discover this only after their text-streaming UX is already shipped and they try to add a structured output feature on top.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T22:37:25.917494+00:00— report_created — created