GenAI-Data-Security-Initiative icon indicating copy to clipboard operation
GenAI-Data-Security-Initiative copied to clipboard

Best Practices v2, Part 5 (Chapter 11): filtering streamed output across chunk boundaries

Open ninadphalak opened this issue 3 weeks ago • 0 comments

Workstream: Risks & Best Practices DSGAI mapping: DSGAI01 (Sensitive Data Leakage)

Part 1 of Best Practices v2 maps DSGAI01 to Chapters 6, 10 and 11, and says Part 5 covers DLP on the output side. The DSGAI 2026 mitigations for DSGAI01 call for real-time DLP on outputs and point to SENSITIVE OUTPUT HANDLING. Neither says what output DLP has to do when the response is streamed, and most chat interfaces and agent runtimes stream.

Here is the problem in one example. The model writes an email address and the stream happens to cut it, so one chunk ends with jane.doe@exa and the next starts with mple.com. A filter that checks each chunk on its own sees two harmless fragments. The user's screen joins them.

Below is suggested text for the output chapter (Chapter 11 in Part 5), written in the series' tier and scope format. It reuses the wording the OWASP AI Exchange merged into #SENSITIVE OUTPUT HANDLING this autumn. If Part 5 is already frozen, I'm glad to send it as review comments in the draft instead, or to keep it for a later revision.

Suggested text

Streamed output

Most chat interfaces and agent runtimes send the response to the user in chunks (token by token, or a few tokens at a time) while the model is still writing it. Output DLP has to work on that stream, because by the time the full response exists, most of it has already been shown.

Why chunk-by-chunk filtering fails: a sensitive value can be split across two or more chunks so that no single chunk matches. Filtering each chunk on its own, or adding a fixed number of characters from the previous chunk before filtering, does not prevent this: by the time the combined text is checked, the first part has already been sent, even though the filter may log a successful detection. A fixed carry-over also has no safe size for values with no maximum length, such as JWTs, some API keys and PEM blocks.

Tier 1 (Foundational)

  • Hold back streamed text until no match can still extend into it, or buffer up to a sentence or response boundary, before the output filter releases it. Apply this to every streamed field the client shows or acts on, including tool-call arguments. Scope: Buy and Build. (DSGAI01)
  • Stop the output rather than release held text when the buffer reaches its size limit while a match may still be open. Scope: Build.
  • When the filter is bought as part of a gateway or guardrail product, ask the vendor whether it inspects streamed responses, and what happens to a value split across two chunks. Scope: Buy.

Tier 2 (Hardening)

  • Test the filter at every split point. For every way of splitting the same text into chunks, the streamed output should equal the output of filtering the whole text at once. Use test values longer than any carry-over, and check that held text is released when the stream ends. Scope: Build.
  • Count a detection that fires after part of the value was already sent as a leak in metrics and incident handling. It is not a block. Scope: Build.

References

  • OWASP AI Exchange, #SENSITIVE OUTPUT HANDLING, Implementation, "Filter streamed output across chunk boundaries": https://owaspai.org/go/sensitiveoutputhandling/
  • Split-Boundary Leaks in Streaming Guardrails (report): https://doi.org/10.5281/zenodo.22909585
  • chunk-invariance, a small test that checks a streaming filter gives the same result at every split point: https://pypi.org/project/chunk-invariance/

Disclosure: I wrote the report and the chunk-invariance test listed above. The text does not depend on either of them.

ninadphalak avatar Nov 11 '26 23:11 ninadphalak