Repository navigation
PII Remover: Restrict config to entity_types enum with pattern-based defaults - #165
Merged
Merged
Conversation
…d default - Add PIIEntityType enum; unknown entity types are now rejected. - Default entity_types to the 12 pattern-based types; NER-based PERSON, LOCATION and NRP are opt-in. - Drop threshold, nlp_engine_type and model_name from the API config; they remain PIIRemover constructor params for evals. - Fix placeholder format in docstring and update README. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- use_enum_values on PII config so entity_types are plain strings; removes enum<->str round trip in default and build() - fold ALL_ENTITY_TYPES into DEFAULT_ENTITY_TYPES - merge duplicate threshold bullets in README - test uses NER_ENTITY_TYPES instead of hardcoded set Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one): 1
Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ValidatorCreate allows extra fields, so typos like entity_types=["AADHAR"] were saved and only failed on the first guardrail run. Validate PII configs against PIIRemoverSafetyValidatorConfig before saving. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Prajna1999
approved these changes
Oct 14, 2026
This was referenced Oct 15, 2026
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
Target issue is ProjectTech4DevAI/kaapi-backend#1250
The PII remover config accepted free-form
entity_typesstrings plus engine knobs (threshold,nlp_engine_type,model_name) via the API. Typos like"AADHAR"were saved silently and only failed (or were ignored) at run time, and the default enabled NER-based types (PERSON,LOCATION,NRP), which use an English-only model that is noisy on Indic names and over-redacts.Changes:
PIIEntityTypeenum; configentity_types: List[PIIEntityType]rejects unknown values.POST /guardrails/validators/configs/checkspii_removerpayloads againstPIIRemoverSafetyValidatorConfig, so badentity_typesor unsupported fields return 422 on save, not on the first guardrail run.PERSON,LOCATION,NRPare opt-in.threshold,nlp_engine_type,model_nameremoved from the API config (extra="forbid"rejects them). They remainPIIRemoverconstructor params for evals.use_enum_values=Trueso validated values reach Presidio as plain strings.Opting in to NER types (list replaces the default, so include the pattern types you still want):
{ "name": "pii-with-names", "type": "pii_remover", "stage": "input", "on_fail_action": "fix", "entity_types": ["PERSON", "LOCATION", "PHONE_NUMBER", "EMAIL_ADDRESS", "IN_AADHAAR"] }Checklist
fastapi run --reload app/main.pyordocker compose upin the repository root and test.Notes
PATCHon a validator config does not accept config fields (extra="forbid"); to changeentity_types, delete and recreate the config.NRPis not produced in transformers mode (CoNLL label mapping has no NRP label); spaCy mode only.test_pii_remover.py14/14 pass (run with--noconftest; local test DB missing).🤖 Generated with Claude Code