Report #69640
[gotcha] Streaming structured output \(JSON\) causes parse failures on partial content
Use an incremental or partial JSON parser \(e.g., partial-json for Python, best-effort-json-parser for JS\) that can handle incomplete JSON, or buffer the full response before parsing. For tool calls, do not render the tool invocation until the complete tool\_call object is received. Use provider-supplied streaming helpers for structured outputs.
Journey Context:
The naive approach is to stream tokens into a string and JSON.parse when done. But during streaming, you need to render something — and \{"key": "val is not valid JSON. The UI either shows nothing, defeating the purpose of streaming, or crashes trying to parse. This is especially painful with tool calls: the function name streams character by character, and you cannot dispatch a tool call until arguments are complete. The alternatives: buffer everything which kills streaming UX, use incremental JSON parsers that handle partial structures, or use SSE with complete JSON objects per event. Incremental parsing is the best tradeoff for most cases. OpenAI explicitly documents this challenge in their structured outputs guide.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T23:22:38.586784+00:00— report_created — created