Add opt-in request redaction middleware - #31
Open
jszzr wants to merge 1 commit into
Open
Conversation
jszzr
force-pushed
the
zzr/presidio-redaction
branch
from
June 15, 2026 07:58
0b1b51a to
3463296
Compare
jszzr
marked this pull request as ready for review
June 16, 2026 06:04
Author
|
This PR is intended as the router-side prerequisite for an optional NemoClaw routed-inference pre-cloud redaction integration. The implementation is deliberately opt-in and scoped to the LiteLLM proxy request path so existing deployments keep their current behavior unless |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in local request redaction layer for the in-process LiteLLM proxy path.
When enabled,
/v1/chat/completionsJSON request bodies are redacted before LiteLLM forwards them to an upstream provider.The feature is disabled by default and uses a lazy Presidio backend so existing proxy deployments do not need the optional privacy dependencies unless redaction is explicitly enabled.
The initial default Presidio entity scope is intentionally narrow:
Motivation
The router already sits on the host-side path between local clients and upstream model providers. This change adds a best-effort data minimization hook at that boundary for common prompt-level personal data, while preserving current behavior when the feature is not enabled.
Design
model-router-toolkit[privacy]optional extra for Presidio dependencies.privacymodule with:/v1/chat/completionsMODEL_ROUTER_REDACTION_ENABLED=true.Evaluation context
I evaluated Presidio separately on the first 5,000 examples from
nvidia/Nemotron-PIItest split usingen_core_web_smand threshold0.35. For the comparable entity subset aligned with this PR scope:Selected full span coverage recall:
This is why the initial default scope is limited to common entities where Presidio is useful as a local best-effort backend.
Non-goals
This PR does not claim complete PII protection. It does not add query-aware minimization, output de-anonymization, broad sensitive attribute classification, or custom recognizers for credentials/API keys.
Validation
pytest tests/test_redaction.py tests/test_redaction_middleware.py -q11 passed in 0.11spython -m ruff check src/model_router_toolkit/privacy src/model_router_toolkit/adapters/litellm/proxy.py tests/test_redaction.py tests/test_redaction_middleware.pyAll checks passed!I also tried a broader local run with
pytest -q -m "not slow and not requires_torch"; it failed on pre-existing environment/tooling issues unrelated to this diff:httpx.AsyncClient(app=...)incompatibility andnvidia-smireturning[N/A]for GPU memory on this server.