Skip to content

fix(pii_remover): keep on_fail/stage as enums in the config model - #168

Merged
AkhileshNegi merged 3 commits into
mainfrom
fix/pii-remover-on-fail-enum
Oct 15, 2026
Merged

AkhileshNegi merged 3 commits into
mainfrom
fix/pii-remover-on-fail-enum

Conversation

@AkhileshNegi

@AkhileshNegi AkhileshNegi commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Target issue is #167

Every pii_remover run (saved config or inline) has been failing since #165 with:

Invalid on_fail value: fix. Expected one of: exception, fix, rephrase.

#165 added model_config = ConfigDict(use_enum_values=True) to PIIRemoverSafetyValidatorConfig so Presidio gets plain-string entity types. That setting is model-wide: it also turned the inherited on_fail: GuardrailOnFail and stage: Stage into plain strings. resolve_on_fail() compares self.on_fail == GuardrailOnFail.Fix (plain Enum, no str mixin), so nothing matched and it raised. config.stage.value in the validator-log writer would raise AttributeError the same way.

Existing tests used the default on_fail, which pydantic does not validate, so the enum stayed an enum and the bug was invisible.

Change

  • pii_remover_safety_validator_config.py: drop use_enum_values; build() passes [PIIEntityType(e).value for e in self.entity_types] to Presidio. Enums stay on the model, so request validation ("AADHAR" rejected, backend params rejected) is unchanged.
  • test_pii_remover.py: test_config_explicit_on_fail_resolves parametrised over fix / exception / rephrase. Fails on main, passes here.

Verified

  • uv run pytest app/tests/validators → 145 passed.
  • Local run through GuardrailRequest → build_guard with inline {"type": "pii_remover", "on_fail_action": "fix"}:
    My name is Rahul Sharma from Pune, call 9876543210 or email [email protected]. → … call <PHONE_NUMBER> or email <EMAIL_ADDRESS>.
  • Staging (pre-fix) POST /guardrails job with a PII config → FAILED with the error above; same config will work once this deploys.

Checklist

  • Ran the validator locally and tested.
  • Fixed a bug and added a regression test.

Notes

Only the config model changes; no API shape change. use_enum_values should be avoided on any BaseValidatorConfig subclass for the same reason.

Manual test: minimum inline config per validator

Send to kaapi-guardrails POST / (Bearer auth + X-ORGANIZATION-ID / X-PROJECT-ID). type is the only required key; everything else has a default. on_fail_action is accepted as an alias for on_fail.

Validator Minimum config Defaults you get
Privacy Protection {"type": "pii_remover"} on_fail: fix, 12 pattern-based entity_types
Slur Match {"type": "uli_slur_match"} on_fail: fix, severity: all, languages: ["en", "hi"]
Scope Control {"type": "topic_relevance_llm", "on_fail": "rephrase", "configuration": "politics, elections, religion", "fallback_message": "I can only help with farming questions."} prompt_schema_version: 2, threshold: 2, llm_callable: gpt-4o-mini. rephrase is required for the fallback to be used; with fix a blocked message becomes ""
Gender Neutrality {"type": "gender_assumption_bias"} on_fail: fix, categories: ["all"]

All four in one request (validators run in list order):

{
  "request_id": "manual-1",
  "input": "My name is Rahul Sharma, call 9876543210. Who should I vote for in the next election?",
  "validators": [
    {"type": "pii_remover"},
    {"type": "uli_slur_match"},
    {"type": "topic_relevance_llm", "on_fail": "rephrase",
     "configuration": "politics, elections, religion",
     "fallback_message": "I can only help with farming questions."},
    {"type": "gender_assumption_bias"}
  ]
}

Inputs and expected outputs, one validator at a time:

Validator Input Expected output
pii_remover My name is Rahul Sharma from Pune, call 9876543210 or email [email protected]. My name is Rahul Sharma from Pune, call <PHONE_NUMBER> or email <EMAIL_ADDRESS>.
pii_remover + "entity_types": ["PERSON", "LOCATION", "PHONE_NUMBER", "EMAIL_ADDRESS"] same My name is <PERSON> from <LOCATION>, call <PHONE_NUMBER> or email <EMAIL_ADDRESS>.
uli_slur_match Tu bhenchod hai, bank balance kaise check karu? tu [REDACTED_SLUR] hai, bank balance kaise check karu?
uli_slur_match This is fucking bullshit, what the hell is wrong with this app unchanged (English profanity is not in the slur list; no profanity pass)
uli_slur_match + "severity": "high" Kutta kahin ka, loan status batao unchanged (kutta is severity L; default all redacts it)
uli_slur_match Kaise ho? Meri fasal me keede lag gaye hain. unchanged
topic_relevance_llm (rephrase) Who should I vote for in the next election? I can only help with farming questions.
topic_relevance_llm (rephrase) अगले चुनाव में मुझे किसे वोट देना चाहिए? मैं केवल कृषि से संबंधित सवालों में मदद कर सकता हूँ।
topic_relevance_llm (rephrase) How much urea should I put on wheat? unchanged
gender_assumption_bias The nurse said she would call the doctor, and the engineer brought his laptop. The nurse said they would call the doctor, and the engineer brought their laptop.

🤖 Generated with Claude Code

use_enum_values=True on PIIRemoverSafetyValidatorConfig coerced the inherited
on_fail and stage fields to plain strings. resolve_on_fail() compares against
GuardrailOnFail members, so every explicit on_fail raised "Invalid on_fail
value", and config.stage.value in the log writer raised AttributeError.

Drop use_enum_values and pass entity_types to Presidio as .value strings from
build() instead. Add a regression test covering all three on_fail values.

Closes #167

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 15, 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: 0c7261bc-548f-42e0-bb0f-0ed20fb48b5c

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.

@AkhileshNegi AkhileshNegi self-assigned this Oct 15, 2026
@AkhileshNegi AkhileshNegi added the bug Something isn't working label Oct 15, 2026
@AkhileshNegi
AkhileshNegi merged commit e7b02ee into main Oct 15, 2026
2 checks passed
@AkhileshNegi
AkhileshNegi deleted the fix/pii-remover-on-fail-enum branch October 15, 2026 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants