Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

PII Remover: Fix validator on_fail error

未关闭
#167 0 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 3 天内回复

@AkhileshNegi 已经在做这个了。

开始于 2026年10月15日。

评估

这个 Issue 还没有评估数据。

描述

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.

主要语言
Python
星标
5
派生
4
平均合并
6 天 1 小时
30 天内合并 PR
10

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ProjectTech4DevAI/kaapi-guardrails 的其他 Issue

查看 ProjectTech4DevAI/kaapi-guardrails 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。