Skip to content

feat(analyzer): add recognizer-level threshold config#2116

Open
rodboev wants to merge 9 commits into
data-privacy-stack:mainfrom
rodboev:pr/recognizer-threshold-config
Open

feat(analyzer): add recognizer-level threshold config#2116
rodboev wants to merge 9 commits into
data-privacy-stack:mainfrom
rodboev:pr/recognizer-threshold-config

Conversation

@rodboev

@rodboev rodboev commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Change Description

Adds recognizer-level score thresholds in presidio-analyzer. Each recognizer entry can set a default threshold and entity-specific overrides, while AnalyzerEngine keeps final filtering after context enhancement and before duplicate removal.

recognizer_registry:
  recognizers:
    - name: CreditCardRecognizer
      type: predefined
      score_thresholds:
        default: 0.4
        CREDIT_CARD: 0.7

RecognizerRegistryProvider validates and attaches normalized thresholds to each recognizer instance. The analyzer resolves the producing recognizer by recognizer_identifier, so same-name recognizers, programmatic recognizers, and request-only ad hoc recognizers retain independent policies.

Precedence is explicit request score_threshold, entity override, recognizer default, then default_score_threshold. The former top-level recognizer_score_thresholds key is removed because this PR has not merged.

This updates the analyzer and registry configuration docs, no-code example, default YAML examples, and changelog.

Issue reference

Fixes #1572

Tests

  • poetry run pytest tests/test_entity_recognizer.py tests/test_yaml_recognizer_models.py tests/test_recognizers_loader_utils.py tests/test_recognizer_registry_provider.py tests/test_recognizer_registry.py tests/test_configuration_validator.py tests/test_analyzer_engine.py tests/test_analyzer_engine_provider.py -q with 303 passed and 1 skipped
  • poetry run ruff check presidio_analyzer/score_thresholds.py presidio_analyzer/entity_recognizer.py presidio_analyzer/analyzer_engine.py presidio_analyzer/analyzer_engine_provider.py presidio_analyzer/input_validation/schemas.py presidio_analyzer/input_validation/yaml_recognizer_models.py presidio_analyzer/recognizer_registry/recognizer_registry_provider.py presidio_analyzer/recognizer_registry/recognizers_loader_utils.py presidio_analyzer/recognizer_registry/recognizer_registry.py tests/test_entity_recognizer.py tests/test_yaml_recognizer_models.py tests/test_recognizers_loader_utils.py tests/test_recognizer_registry_provider.py tests/test_recognizer_registry.py tests/test_configuration_validator.py tests/test_analyzer_engine.py tests/test_analyzer_engine_provider.py

Note on CHANGELOG

Updated CHANGELOG.md under [unreleased], Analyzer, Added.

Checklist

  • I have reviewed the contribution guidelines
  • I agree to follow this project's Code of Conduct
  • I confirm that I have the right to submit this contribution and that it does not knowingly contain proprietary or confidential code.
  • My code includes unit tests
  • All unit tests and lint checks pass locally
  • My PR contains documentation updates / additions if required

Copilot AI review requested due to automatic review settings June 28, 2026 04:08
@rodboev

rodboev commented Jun 28, 2026

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support in presidio-analyzer for configuring score thresholds per recognizer (and optionally per entity within that recognizer) via YAML, while preserving the existing global default_score_threshold / request-level score_threshold behavior.

Changes:

  • Introduces recognizer_score_thresholds configuration, applies it during result filtering (before duplicate collapse) when no request-level score_threshold is provided.
  • Adds validation/normalization for the new configuration shape (including numeric shorthand) and expands unit test coverage for precedence and error cases.
  • Updates analyzer configuration docs, the no-code tutorial, and the root changelog to document the new option.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
presidio-analyzer/presidio_analyzer/analyzer_engine.py Adds recognizer/entity-specific threshold support and applies filtering before deduplication.
presidio-analyzer/presidio_analyzer/analyzer_engine_provider.py Loads recognizer_score_thresholds from analyzer YAML and passes it into AnalyzerEngine.
presidio-analyzer/presidio_analyzer/input_validation/schemas.py Validates and normalizes recognizer_score_thresholds in analyzer configuration validation.
presidio-analyzer/presidio_analyzer/conf/default_analyzer_full.yaml Documents the new YAML option with a commented example.
presidio-analyzer/tests/test_analyzer_engine.py Adds deterministic tests covering precedence, shorthand, invalid values, and dedupe ordering.
presidio-analyzer/tests/test_analyzer_engine_provider.py Verifies provider passes/normalizes thresholds from YAML and that defaults remain unchanged otherwise.
presidio-analyzer/tests/test_configuration_validator.py Adds validator tests for valid shorthand + invalid threshold structures/types/ranges.
docs/tutorial/08_no_code.md Updates no-code YAML example and explains when to use recognizer-level thresholds.
docs/analyzer/analyzer_engine_provider.md Documents the new configuration key and provides a YAML example.
CHANGELOG.md Adds an Unreleased entry documenting the new analyzer YAML capability.

Comment thread presidio-analyzer/presidio_analyzer/input_validation/schemas.py Outdated
Comment thread presidio-analyzer/presidio_analyzer/analyzer_engine.py Outdated
Comment thread presidio-analyzer/presidio_analyzer/analyzer_engine.py Outdated
Comment thread presidio-analyzer/presidio_analyzer/analyzer_engine.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Comment thread presidio-analyzer/presidio_analyzer/input_validation/schemas.py Outdated
Comment thread presidio-analyzer/presidio_analyzer/input_validation/schemas.py Outdated
Comment thread presidio-analyzer/presidio_analyzer/analyzer_engine.py Outdated
@rodboev rodboev force-pushed the pr/recognizer-threshold-config branch from 9ebc0e8 to adac24d Compare July 9, 2026 17:29
Comment thread docs/analyzer/analyzer_engine_provider.md Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recognizer-level thresholds

3 participants