Skip to content

PII Remover: Fix validator on_fail error #167

Open

Description

@AkhileshNegi

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_values from PIIRemoverSafetyValidatorConfig.
  • Convert entity_types to .value strings in the build() method before passing to Presidio.
  • Maintain enum types for strict validation in the model.
  • Add a regression test to validate all three on_fail values.
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() compares self.on_fail == GuardrailOnFail.Fix. GuardrailOnFail is a plain Enum (no str mixin), so "fix" != GuardrailOnFail.Fix and the method falls through to raise ValueError(...).
  • routes/guardrails.py calls config.stage.value when writing validator logs; with stage coerced to "input" this raises AttributeError: '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.

Activity

  1. changed the title [-]pii_remover: every stored/inline config fails with 'Invalid on_fail value: fix'[/-] [+]PII Remover: Fix validator on_fail error[/+] on Oct 15, 2026
  2. self-assigned this
    on Oct 15, 2026
  3. moved this from To Do to In Progress in Kaapi-devon Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

  • Status
    In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions