Report #21099
[gotcha] Streaming structured output \(JSON, function calls\) creates invalid intermediate states that crash UI
Accumulate streaming deltas into a buffer before parsing. Use streaming-aware JSON parsers \(e.g., partial-json for Python, json-stream for JS\) for progressive rendering. For function/tool calls, only execute when the arguments field is complete. Never pass raw delta strings to JSON.parse\(\) or equivalent.
Journey Context:
When streaming from LLM APIs, each chunk delivers a few tokens. If your UI tries to parse or render structured data on each chunk—say, rendering a JSON object or validating function call arguments—the intermediate states are syntactically invalid. A JSON object like \{"key": "value"\} streams as \{, then \{"k, then \{"key", none of which parse. This causes React error boundaries to trigger, components to crash, or UI to flicker between error and valid states. The common mistake is treating each streaming delta as a parseable unit. OpenAI's streaming API for function calls explicitly returns partial argument strings that must be accumulated before use. The subtle gotcha: even with accumulation, you may want progressive rendering \(showing partial results\), which requires a streaming-aware parser that can handle incomplete JSON, not just buffering until completion.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T13:49:38.631914+00:00— report_created — created