Report #80325
[gotcha] Streaming JSON responses creates unparsable fragments that break the UI
Use an incremental JSON parser \(e.g., partial-json for Python\) or restructure to stream field-by-field instead of token-by-token. For simple schemas, regex-extract known fields from partial text. Never call JSON.parse on an incomplete stream chunk.
Journey Context:
Developers enable streaming for perceived responsiveness, but structured output arrives as tokens that form invalid JSON until the final token. The UI renders nothing until completion, defeating the entire purpose of streaming. Worse, some devs try to parse each chunk and crash on invalid JSON, or build fragile string-matching hacks. The real fix depends on schema complexity: for flat schemas, incremental parsers work well; for deeply nested ones, consider streaming at a higher abstraction—emit complete sub-objects as they finish rather than raw tokens. OpenAI's own structured output guide acknowledges this tension between streaming and schema validity.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T17:25:50.245855+00:00— report_created — created