feat(governance): pre-LLM privacy gate for the R2 mechanical regime#7
Open
sammy995 wants to merge 8 commits into
Open
feat(governance): pre-LLM privacy gate for the R2 mechanical regime#7sammy995 wants to merge 8 commits into
sammy995 wants to merge 8 commits into
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
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.
Description
Adds a pre-LLM privacy gate to the R2 mechanical regime. It reversibly tokenizes direct identifiers (EMAIL, PHONE, SSN, PAN, IBAN, IP) so the model never sees raw personal data, and mechanically DEFERs (
PRIV_0) a case when residual identifiers exceed a configurable budget or detection fails (fail-closed). This adds a data-minimization dimension (GDPR Art. 5(1)(c) / OWASP LLM06).The new primitive mirrors the existing
hard_gates/i6qshape (config dataclass + result dataclass + pure functions) and slots into the documented pipeline as a new stage:R2 decisions are driven by
risk_score/regulatory_flags, not identities, so tokenization does not affect outcomes. The reversible token map stays in-memory and is never written toDecisionResult/to_dict()or logs — only integer counts (privacy_entities_found,privacy_residual_pii) go intometadata.This is PR#1 of 2. A follow-up adds a Privacy Leakage Rate metric (alongside CDL/DIU), synthetic narrative data that exercises the gate end-to-end, an optional NER recognizer behind a
[privacy-ner]extra, and R1/R3 coverage via anLLMInterfacewrapper.What's included
governance/primitives/privacy_gate.py—PrivacyConfig,PrivacyResult,RegexRecognizer, pluggablePiiRecognizer,scan_and_tokenize,detokenize,privacy_gate.PrivacyConfig(enabled=False)).tests/test_privacy_gate.py— 19 offline tests (recognizer, reversible tokenization, residual fail-safe, fail-closed, R2 integration, serialization-safety).examples/privacy_demo.py(offline) and a CHANGELOG entry.Related issue
Closes #6
Type of change
Vendor-neutral core
Checklist
ruff check .andblack --check .passmypy srcpassespytestpasses (tests run offline with themockprovider)Open items for maintainers
PRIV_0vs theK0_xtaxonomy — happy to rename.PrivacyConfig.enableddefaults toTrue(adds two integer metadata keys; no behavior change on the current synthetic dataset, which has no free-text PII). Can default to opt-in if preferred.