Skip to content

fix(analyzer): skip SpacyRecognizer for SlimSpacyNlpEngine#2168

Open
ultramancode wants to merge 1 commit into
data-privacy-stack:mainfrom
ultramancode:fix/slim-supported-entities-contract
Open

fix(analyzer): skip SpacyRecognizer for SlimSpacyNlpEngine#2168
ultramancode wants to merge 1 commit into
data-privacy-stack:mainfrom
ultramancode:fix/slim-supported-entities-contract

Conversation

@ultramancode

Copy link
Copy Markdown
Contributor

Change Description

SlimSpacyNlpEngine disables NER, but the recognizer registry treated it like a regular spaCy engine and added SpacyRecognizer.

When SpacyRecognizer received an empty supported-entities list from the slim engine, it fell back to its default entities. As a result, the registry reported NER entities that the slim engine could not produce.

When SlimSpacyNlpEngine is used, the registry no longer adds SpacyRecognizer automatically.
If SpacyRecognizer is explicitly configured, analyzer initialization fails because the slim engine does not produce the NER results it requires.

This does not affect tokenization, lemmatization, or context-based score enhancement provided by the slim engine.

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

if isinstance(nlp_engine, _NLP_ENGINES_WITHOUT_NER_OUTPUT):
self.validate_nlp_engine_compatibility(nlp_engine)
logger.info("Skipping NLP recognizer registration for no-op NLP engine.")
logger.info(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could be a debug message


logger = logging.getLogger("presidio-analyzer")

_NLP_ENGINES_WITHOUT_NER_OUTPUT = (

@omri374 omri374 Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This list is a good start, but it's (a) hard to maintain (we might forget to update it) and (b) hard to customize for a user downloading from pypi and adding a custom Nlp Engine.
Here's my suggestion. In NlpEngine, add a has_ner property

class NlpEngine(ABC):
    ...
    @property
    def has_ner(self) -> bool:
        """Returns True if this engine performs Named Entity Recognition natively."""
        return False

And use this to filter out the SpacyRecognizer

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.

2 participants