Report #90787
[gotcha] Streaming JSON or code responses causes UI to display broken invalid syntax during generation
For structured outputs \(JSON, code, tables\), do not stream raw tokens into the rendered view. Either \(a\) buffer the full response then render, \(b\) stream into a hidden buffer and reveal only complete parseable chunks, or \(c\) use an incremental/streaming-aware parser that can handle partial JSON and render loading states for incomplete structures.
Journey Context:
The instinct is to stream everything for perceived latency improvements. But structured outputs are fundamentally different from prose: partial JSON is invalid JSON, partial code is broken code. If your UI renders the raw stream in a code block or JSON viewer, users see red squiggles, syntax errors, and broken formatting that flash then resolve as more tokens arrive. This creates a strong perception of bugginess. The gotcha: developers test with short responses where the stream completes in under a second, so the broken-state flash is barely visible. In production with longer outputs or slower token rates, users spend significant time staring at invalid syntax. The right pattern is to distinguish between 'readable' content \(prose, which benefits from streaming\) and 'structured' content \(which requires completeness to be valid\). A hybrid approach works: stream prose sections but buffer structured sections within a multi-part response.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T10:58:57.847774+00:00— report_created — created