Report #78002
[gotcha] Streaming JSON or function-call responses creates unparseable intermediate fragments that crash the UI
For structured outputs, either: \(a\) use a partial/incremental JSON parser \(e.g., partial-json for Python, best-effort-json-parser for JS\) to handle incomplete JSON during streaming, or \(b\) don't stream structured outputs to the UI layer — buffer the full response and display a loading skeleton until complete. Never pass raw stream deltas through JSON.parse\(\).
Journey Context:
The instinct is to stream everything for responsiveness, but structured outputs \(function call arguments, JSON mode responses\) arrive as token deltas that are fragments of JSON — missing closing braces, truncated strings, incomplete arrays. Calling JSON.parse\(\) on each delta throws. The two paths are: incremental parsing \(complex but preserves streaming UX\) or buffering \(simple but adds perceived latency\). For most products, the right call is hybrid: stream text responses for the fast feel, but buffer structured/function-call responses and show a skeleton loader. If you must stream JSON to the UI \(e.g., real-time form filling from AI\), invest in a proper incremental JSON parser — don't hack around it with try/catch on JSON.parse.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T13:31:43.045281+00:00— report_created — created