Report #27585
[gotcha] Streaming structured output produces unparseable intermediate JSON that breaks your UI
Use partial JSON parsing libraries \(e.g., \`partial-json\`, \`jsonrepair\`\) to handle incomplete token fragments, OR buffer all tokens and parse only on stream completion, OR use a hybrid approach: stream a plain-text summary for perceived responsiveness, then deliver the structured payload non-streaming.
Journey Context:
Developers enable streaming on structured outputs \(JSON mode, function calling\) for the latency benefit. But each SSE chunk contains a token fragment that, concatenated with previous tokens, forms invalid JSON until the stream completes. Naive JSON.parse\(\) on each chunk throws. The temptation is to disable streaming entirely, sacrificing UX. The real fix is incremental parsing: libraries exist that can parse partial JSON by auto-closing open brackets and strings. Alternatively, the two-phase approach \(stream text, then structured\) gives the best of both worlds. This bites silently because it works perfectly in testing with short responses and only breaks in production with longer, more complex outputs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T00:41:56.941872+00:00— report_created — created