Skip to content

Warn about unsupported requested entities while preserving partial results - #2259

Open
nikolas-sapa wants to merge 2 commits into
data-privacy-stack:mainfrom
nikolas-sapa:fix/error-on-unsupported-entities
Open

nikolas-sapa wants to merge 2 commits into
data-privacy-stack:mainfrom
nikolas-sapa:fix/error-on-unsupported-entities

Conversation

@nikolas-sapa

@nikolas-sapa nikolas-sapa commented Sep 16, 2026

Copy link
Copy Markdown

Summary

Refs #2256. Following the maintainer request for a staged change, preserve the existing behavior for requests containing both supported and unsupported entities.

The existing registry warning now explains that ignoring unsupported entities is deprecated and will raise an error in a future version. It identifies the entity and language, and directs callers to AnalyzerEngine.get_supported_entities(language) or a matching recognizer. No release date or configuration option is introduced.

Compatibility

  • Supported entities still produce the same results in mixed requests.
  • Requests with no matching recognizers retain the existing ValueError and message.
  • Ad-hoc recognizers remain included in entity matching.
  • The proposed REST ValueError-to-400 mapping has been removed. Existing error response statuses remain unchanged.
  • Public method docstrings describe the warning and current behavior.

Verification

  • The new mixed-entity registry regressions failed against the previous hard-error implementation before the fix.
  • Full registry and Flask test suites: 58 passed on Python 3.12.13, rerun after the final assertion change.
  • Focused engine checks: 20 passed in independent review; add-recognizer regression also passed separately.
  • Tests exercise real CreditCardRecognizer and IbanRecognizer implementations with NoOpNlpEngine. Flask tests replace engine provisioning but use real analysis and response serialization.
  • uv run --no-sync ruff check . and git diff --check passed. Ruff retains the repository-configured test exclusions.

The full analyzer suite, model-dependent tests, and live-server E2E suite were not run. E2E expectations were aligned with the preserved API behavior; those changes are not claimed as live-server verified.

Scope

No country-recognizer language configuration changes, new strictness option, or changelog edits. This supersedes the initial hard-error implementation.

The analyzer silently ignored requested entities that no recognizer could
serve in the requested language, returning 200 with partial results. In
gateway/DLP setups this fails open: an operator adds an entity to the
block list, the service keeps answering successfully, and that entity is
never scanned. The behavior was inconsistent too, since requesting only
unsupported entities already raised an error.

RecognizerRegistry.get_recognizers now collects the requested entities
that have no matching recognizer for the language and raises a ValueError
listing them, so the failure is explicit and actionable. The REST API maps
the ValueError to a 400 response instead of a 500.

Zero-shot recognizers are unaffected: LMRecognizer requires
supported_entities and filters requests against them, and generic
consolidation adds GENERIC_PII_ENTITY to that list, so every entity a
zero-shot recognizer can serve is reported by get_supported_entities.

Note for the reviewer: the behavior change also affects two existing engine
tests which used a not-yet-registered entity; they now assert the raised
error, which makes the documented contract explicit.
@nikolas-sapa
nikolas-sapa force-pushed the fix/error-on-unsupported-entities branch from 890afe5 to 31c887a Compare September 16, 2026 12:32
@omri374

omri374 commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

As disccused on #2256, this is not backward compatible. It's best if this is done in stages, where the first stage is a warning + a notice that this would raise a warning in future versions. wdyt?

@nikolas-sapa nikolas-sapa changed the title Raise an error when requested entities are unsupported for the language Warn about unsupported requested entities while preserving partial results Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants