Skip to content

PII Remover: Restrict config to entity_types enum with pattern-based defaults - #165

Merged
AkhileshNegi merged 4 commits into
mainfrom
enhancement/pii-validator
Oct 14, 2026
Merged

AkhileshNegi merged 4 commits into
mainfrom
enhancement/pii-validator

Conversation

@AkhileshNegi

@AkhileshNegi AkhileshNegi commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Target issue is ProjectTech4DevAI/kaapi-backend#1250

The PII remover config accepted free-form entity_types strings 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:

  • New PIIEntityType enum; config entity_types: List[PIIEntityType] rejects unknown values.
  • Validation at create time: POST /guardrails/validators/configs/ checks pii_remover payloads against PIIRemoverSafetyValidatorConfig, so bad entity_types or unsupported fields return 422 on save, not on the first guardrail run.
  • Default is now pattern/regex-based types only (matches the default list in #1250). PERSON, LOCATION, NRP are opt-in.
  • threshold, nlp_engine_type, model_name removed from the API config (extra="forbid" rejects them). They remain PIIRemover constructor params for evals.
  • Config uses use_enum_values=True so validated values reach Presidio as plain strings.
  • README updated: threshold is only effective in transformers mode (spaCy scores every NER hit 0.85; pattern recognizers aren't thresholded).

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

  • Ran fastapi run --reload app/main.py or docker compose up in the repository root and test.
  • If you've fixed a bug or added code that is tested and has test cases.

Notes

  • No backward compatibility needed: PII configs created with this change are the first in use.
  • PATCH on a validator config does not accept config fields (extra="forbid"); to change entity_types, delete and recreate the config.
  • NRP is not produced in transformers mode (CoNLL label mapping has no NRP label); spaCy mode only.
  • Tests: test_pii_remover.py 14/14 pass (run with --noconftest; local test DB missing).

🤖 Generated with Claude Code

AkhileshNegi and others added 2 commits October 14, 2026 15:46
…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]>
@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one): 1
  • ready-for-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository: ProjectTech4DevAI/kaapi-guardrails/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d02a086c-0c41-478e-90b3-3f400c85c511

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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]>
@AkhileshNegi AkhileshNegi self-assigned this Oct 14, 2026
@AkhileshNegi AkhileshNegi added the enhancement New feature or request label Oct 14, 2026
@github-project-automation github-project-automation Bot moved this to To Do in Kaapi-dev Oct 14, 2026
@Prajna1999 Prajna1999 moved this from To Do to In Review in Kaapi-dev Oct 14, 2026
@AkhileshNegi
AkhileshNegi merged commit e5af46d into main Oct 14, 2026
2 checks passed
@AkhileshNegi
AkhileshNegi deleted the enhancement/pii-validator branch October 14, 2026 13:25
@github-project-automation github-project-automation Bot moved this from In Review to Closed in Kaapi-dev Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

2 participants