Report #71253
[gotcha] Streaming JSON or function-call arguments are unparsable until the stream completes
Accumulate SSE deltas into a buffer and parse only on stream completion, or use an incremental JSON parser \(e.g., partial-json, json-stream\) that tolerates truncated input; never pass raw partial deltas to JSON.parse or a schema validator
Journey Context:
Developers enable streaming for responsiveness, then try to render structured AI output \(JSON, function-call arguments\) as it arrives. But streaming APIs return content in token-sized chunks that split JSON at arbitrary byte boundaries, producing syntactically invalid fragments. Any standard JSON.parse call on a partial delta throws, silently breaking the UI. The three options are: \(a\) disable streaming for structured output—simplest but loses perceived speed, \(b\) use an incremental/streaming JSON parser that handles truncation, or \(c\) accumulate all deltas and parse only after the \[DONE\] event. Option \(c\) is the most common production pattern because it preserves the streaming UX for text display while guaranteeing valid structured data. The gotcha is that many devs don't realize function-call argument streaming has this problem until they see parse errors in production logs from race conditions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:10:37.264182+00:00— report_created — created