Report #40187
[gotcha] Streaming structured AI output \(JSON, XML\) breaks UI during partial render
Use an incremental or partial JSON parser that can handle incomplete JSON \(e.g., partial-json, json-repair, or instructor's streaming mode\). Alternatively, buffer tokens until you have a complete valid object before rendering. Never attempt JSON.parse\(\) on each streaming chunk.
Journey Context:
The instinct is to stream everything for perceived speed. But structured outputs arrive as token fragments—half a JSON object cannot be parsed. Teams discover this when their UI flickers, crashes, or shows undefined mid-stream. The tradeoff: buffering kills the streaming UX benefit, but naive streaming breaks the UI entirely. The solution is incremental parsing—libraries that maintain a state machine over partial JSON and yield the best-effort parsed object at each step. This gives you streaming UX with structural safety. OpenAI's own SDK handles this with partial JSON parsing in streaming mode for structured outputs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T21:55:40.327718+00:00— report_created — created