Report #45298
[gotcha] Streaming structured output \(JSON, code\) token-by-token before validation causes broken rendering
For structured outputs \(JSON, code blocks, tables\), buffer at the block or statement level rather than the token level. Do not render opening JSON braces or code fences until you have enough tokens to display a complete, syntactically valid block. Use a reduced-opacity preview state for in-progress structured content, and only commit to full rendering when the block is complete enough to parse correctly.
Journey Context:
Streaming raw tokens works great for natural language prose — partial sentences are readable and users can start processing immediately. But for structured output, token-level streaming creates broken intermediate states: half-rendered JSON that fails parsing, code blocks with incomplete syntax that break syntax highlighting, tables with missing columns. Users see broken formatting and assume the output is wrong even when the final result would be valid. The trap: waiting for the full response before showing anything defeats the purpose of streaming and feels slow. The right balance: stream natural language commentary token-by-token, but buffer structured blocks until they are complete enough to render correctly. This is especially critical with function calling and JSON mode where partial JSON is unparseable and can crash client-side code.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T06:30:02.126626+00:00— report_created — created