Repository navigation
fix(pii_remover): keep on_fail/stage as enums in the config model - #168
Merged
Merged
Conversation
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 <noreply@anthropic.com>
|
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 |
4 tasks done
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Prajna1999
approved these changes
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 #167
Every
pii_removerrun (saved config or inline) has been failing since #165 with:#165 added
model_config = ConfigDict(use_enum_values=True)toPIIRemoverSafetyValidatorConfigso Presidio gets plain-string entity types. That setting is model-wide: it also turned the inheritedon_fail: GuardrailOnFailandstage: Stageinto plain strings.resolve_on_fail()comparesself.on_fail == GuardrailOnFail.Fix(plainEnum, nostrmixin), so nothing matched and it raised.config.stage.valuein the validator-log writer would raiseAttributeErrorthe 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: dropuse_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_resolvesparametrised overfix/exception/rephrase. Fails onmain, passes here.Verified
uv run pytest app/tests/validators→ 145 passed.GuardrailRequest→build_guardwith inline{"type": "pii_remover", "on_fail_action": "fix"}:My name is Rahul Sharma from Pune, call 9876543210 or email rahul@example.com.→… call <PHONE_NUMBER> or email <EMAIL_ADDRESS>.POST /guardrailsjob with a PII config →FAILEDwith the error above; same config will work once this deploys.Checklist
Notes
Only the config model changes; no API shape change.
use_enum_valuesshould be avoided on anyBaseValidatorConfigsubclass for the same reason.Manual test: minimum inline config per validator
Send to kaapi-guardrails
POST /(Bearer auth +X-ORGANIZATION-ID/X-PROJECT-ID).typeis the only required key; everything else has a default.on_fail_actionis accepted as an alias foron_fail.{"type": "pii_remover"}on_fail: fix, 12 pattern-basedentity_types{"type": "uli_slur_match"}on_fail: fix,severity: all,languages: ["en", "hi"]{"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.rephraseis required for the fallback to be used; withfixa blocked message becomes""{"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:
pii_removerMy name is Rahul Sharma from Pune, call 9876543210 or email rahul@example.com.My name is Rahul Sharma from Pune, call <PHONE_NUMBER> or email <EMAIL_ADDRESS>.pii_remover+"entity_types": ["PERSON", "LOCATION", "PHONE_NUMBER", "EMAIL_ADDRESS"]My name is <PERSON> from <LOCATION>, call <PHONE_NUMBER> or email <EMAIL_ADDRESS>.uli_slur_matchTu bhenchod hai, bank balance kaise check karu?tu [REDACTED_SLUR] hai, bank balance kaise check karu?uli_slur_matchThis is fucking bullshit, what the hell is wrong with this appuli_slur_match+"severity": "high"Kutta kahin ka, loan status bataokuttais severity L; defaultallredacts it)uli_slur_matchKaise ho? Meri fasal me keede lag gaye hain.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?gender_assumption_biasThe 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