Report #57819
[gotcha] Streaming tokens to UI before content moderation completes
Implement a buffering layer that holds N tokens before rendering, paired with a sliding-window moderation check on accumulated text. For strict safety requirements, buffer the entire response before display. At minimum, run full moderation on the completed response and implement a UI mechanism to retroactively retract flagged content.
Journey Context:
Developers reach for streaming to reduce perceived latency, but moderation APIs evaluate complete text. When you stream token-by-token, harmful content reaches the user before moderation can flag it. The naive approach—moderate after completion—means you've already displayed the harmful content. The tradeoff is between perceived latency \(stream immediately\) and safety \(buffer first\). Full buffering eliminates the streaming UX benefit; no buffering creates safety gaps. For most products, a small buffer \(2-3 sentences\) plus post-completion moderation with a retraction mechanism is the right balance. Teams get burned when they assume the moderation API runs in parallel with streaming and catches issues in real-time—it doesn't.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:32:13.326321+00:00— report_created — created