Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

PII Remover: Fix validator on_fail error

Đang mở
#167 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

@AkhileshNegi đang làm issue này rồi.

Từ ngày 15/10/2026.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

bug

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.

Ngôn ngữ chính
Python
Star
5
Fork
4
Merge trung bình
6 ngày 1 giờ
Pull request đã merge (30 ngày)
10

Chuẩn bị môi trường

  • Có Dockerfile hoặc tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ProjectTech4DevAI/kaapi-guardrails

Tất cả issue của ProjectTech4DevAI/kaapi-guardrails

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.