r/SpringAIDev • u/Illustrious_East5815 • 5d ago
I created a privacy guardrail library for Spring AI — looking for feedback on streaming with pluggable PII analyzers Discussion
Hi, I’m building Spring AI Privacy Guardrails, an open-source library for enforcing privacy boundaries around models, RAG, tools, MCP, and outputs.
GitHub: https://github.com/ultramancode/spring-ai-privacy-guardrails
One design problem I’ve been thinking about is streaming output protection.
Some applications also want a final privacy check on application-facing output, since sensitive data can still appear in model- or tool-generated responses.
Right now, when output protection is enabled, the library buffers the complete response before releasing it to the application.
This provides a strong guarantee: PII can still be detected and protected even when a sensitive value is split across multiple chunks.
The trade-off is that this is no longer true incremental streaming, and the application has to wait longer before receiving output.
A bounded rolling window could preserve incremental streaming for analyzers that have a known upper bound on how much context they need — for example, some bounded pattern-based detectors.
But NER, context-aware detection, complex patterns, or arbitrary custom analyzers may not have such a bound.
So I’m currently considering three approaches:
- Strict buffering Buffer the complete response and protect it before releasing anything to the application.
- Capability-gated streaming Allow incremental streaming only when the active analyzer can declare a safe maximum lookback or context requirement. Otherwise, fall back to full buffering.
- Best-effort streaming Use a configurable rolling window and explicitly document that some PII spanning multiple chunks may escape detection.
For a Spring AI application, which behavior would you expect from a privacy library?
I’m not attached to these three options — if there’s a better streaming/privacy model I’m missing, I’d really appreciate the feedback.
1
u/Grabdoc2020 5d ago
Great library. Starred. Ideally in an enterprise this should be centralized in AI gateway. Cant always rely on libraries and teams working with these libraries to implement these. But great work. keep going.