百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
返回工具页/返回 Issues 列表
#2391·Guardrails

错误: 使用自定义识别器进行 Presidio 敏感数据检测不能两次调用

作者: RobGeada创建于 2026年9月17日更新于 2026年9月17日
标签bugstatus: needs triage

Describe the bug When using a custom Presidio recognizer, e.g.: rails: input: flows: - mask sensitive data on input config: sensitive_data_detection: recognizers: - name: "Canadian Passport" supported_entity: "CA_PASSPORT" patterns: - name: "canada_passport_regex" regex: "(\b[A-Z]{2}[0-9]{6}\b)" score: 1 You can only call this config once. On the second call, Presidio will throw a type error: ERROR: nemoguardrails.actions.action_dispatcher: presidio_analyzer.pattern.Pattern() argument after ** must be a mapping, not Pattern Traceback (most recent call last): File "/.../NeMo-Guardrails/nemoguardrails/actions/action_dispatcher.py", line 357, in execute_action result = await result ^^^^^^^^^^^^ File "/.../NeMo-Guardrails/nemoguardrails/library/sensitive_data_detection/actions.py", line 200, in mask_sensitive_data ad_hoc_recognizers=_get_ad_hoc_recognizers(sdd_config), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/.../NeMo-Guardrails/nemoguardrails/library/sensitive_data_detection/actions.py", line 97, in _get_ad_hoc_recognizers ad_hoc_recognizers.append(PatternRecognizer.from_dict(recognizer)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/.../nemo-guardrails-local-dev/.venv/lib/python3.12/site-packages/presidio_analyzer/pattern_recognizer.py", line 271, in from_dict patterns_list = [Pattern.from_dict(pat) for pat in patterns] ^^^^^^^^^^^^^^^^^^^^^^ File "/.../nemo-guardrails-local-dev/.venv/lib/python3.12/site-packages/presidio_analyzer/pattern.py", line 38, in from_dict return cls(**pattern_dict) ^^^^^^^^^^^^^^^^^^^ TypeError: presidio_analyzer.pattern.Pattern() argument after ** must be a mapping, not Pattern This is because the Presidio PatternRecognizer.from_dict(recognizer) function modifies the passed recognizer object, and renders it incompatible with a second call to the function. To remedy this, pass a copy of the recognizer dict to the function. Will open a PR shortly.

内容来源: NVIDIA-NeMo/Guardrails

查看 GitHub 原文在 GitHub 查看讨论