Report #77498
[gotcha] Null content deltas in streaming render as literal 'null' string in UI
Always null-check the content delta before appending to UI: \`if \(delta.content \!= null\) \{ append\(delta.content\) \}\`. Never use string concatenation or interpolation that coerces null to the string 'null'.
Journey Context:
In OpenAI's streaming API, when the model invokes a tool call or enters a reasoning phase, \`choices\[0\].delta.content\` is JSON \`null\`, not an empty string. The classic bug: JavaScript code like \`output \+= chunk.choices\[0\].delta.content\` silently coerces \`null\` to the literal string 'null', which appears in the rendered output. This is especially sneaky because it only manifests when the model uses tools or reasoning—pure text responses always have string content. Developers test with simple text prompts, ship, and then get bizarre 'null' artifacts in production when tool calls or extended thinking are triggered. The fix is trivial but the diagnosis is not—teams often chase rendering bugs, encoding issues, or API version mismatches before finding the null coercion.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T12:40:37.304848+00:00— report_created — created