Repository navigation
PII Remover: Fix validator on_fail error #167
Description
Is your feature request related to a problem?
Running any pii_remover validator fails at run time with an invalid on_fail value. This causes job failures and prevents users from processing configurations correctly.
Describe the solution you'd like
- Remove
use_enum_valuesfromPIIRemoverSafetyValidatorConfig. - Convert
entity_typesto.valuestrings in thebuild()method before passing to Presidio. - Maintain enum types for strict validation in the model.
- Add a regression test to validate all three
on_failvalues.
Original issue
Bug
Running any pii_remover validator (saved config or inline) fails at run time:
Invalid on_fail value: fix. Expected one of: exception, fix, rephrase.
Reproduced on staging via kaapi-backend POST /guardrails with a PII config (on_fail_action: fix), job status FAILED, no output.
Root cause
PR #165 added model_config = ConfigDict(use_enum_values=True) to PIIRemoverSafetyValidatorConfig so Presidio receives plain-string entity types. use_enum_values is model-wide, so it also coerces the inherited on_fail: GuardrailOnFail and stage: Stage fields to plain strings.
BaseValidatorConfig.resolve_on_fail()comparesself.on_fail == GuardrailOnFail.Fix.GuardrailOnFailis a plainEnum(nostrmixin), so"fix" != GuardrailOnFail.Fixand the method falls through toraise ValueError(...).routes/guardrails.pycallsconfig.stage.valuewhen writing validator logs; withstagecoerced to"input"this raisesAttributeError: 'str' object has no attribute 'value'.
Unit tests missed it because they relied on the default on_fail; pydantic does not validate defaults, so the enum stayed an enum.
PIIRemoverSafetyValidatorConfig(type="pii_remover", on_fail="fix").resolve_on_fail()
# ValueError: Invalid on_fail value: fix. ...
PIIRemoverSafetyValidatorConfig(type="pii_remover", stage="input").stage.value
# AttributeError: 'str' object has no attribute 'value'Fix
Drop use_enum_values and convert entity_types to .value strings inside build(), right before handing them to Presidio. Enums stay on the model (strict validation unchanged), Presidio still gets plain strings. Add a regression test that passes on_fail explicitly for all three values.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIn Progress
Activity
[-]pii_remover: every stored/inline config fails with 'Invalid on_fail value: fix'[/-][+]PII Remover: Fix validator on_fail error[/+]