r/AI_Agents•
damn_brotha

Most AI privacy leaks happen before the model call. I built a Python layer to mask PII first

Discussion

I kept seeing teams obsess over prompt quality and model choice while sending raw customer data straight to LLM APIs. So I built a small Python package called ShieldPrompt to handle one boring but critical thing: mask sensitive data before it leaves your app, then restore it in the final response. The flow is simple: Detect PII (regex by default, optional NER) Replace with tokens like [EMAIL_ADDRESS_1] Send masked text to LLM Unmask final response using a per-request vault What I wanted was flexibility, so I added multiple integration points: Decorator: @mask_pii(...) for drop-in function wrapping Core engine: direct Shield().mask() / unmask() FastAPI middleware: masks request JSON string fields and unmasks response text CLI for mask/unmask/inspect workflows MCP server tools for agent workflows A couple implementation details that mattered a lot: Right-to-left replacement while masking (prevents index corruption) Length-sorted token restore while unmasking (prevents partial token collisions) Context-local vault isolation for concurrent requests Graceful fallback to regex-only if NER dependencies are not installed It is open source and still early, so I would love practical feedback from people running LLM apps in production: How are you currently handling PII in prompts/responses without adding a ton of complexity?

Posted Apr 9, 2026, 9:15 PM UTC

12
Loading comments…