fix(analyzer): skip SpacyRecognizer for SlimSpacyNlpEngine#2168
Open
ultramancode wants to merge 1 commit into
Open
fix(analyzer): skip SpacyRecognizer for SlimSpacyNlpEngine#2168ultramancode wants to merge 1 commit into
ultramancode wants to merge 1 commit into
Conversation
omri374
reviewed
Jul 16, 2026
| 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( |
omri374
reviewed
Jul 16, 2026
|
|
||
| logger = logging.getLogger("presidio-analyzer") | ||
|
|
||
| _NLP_ENGINES_WITHOUT_NER_OUTPUT = ( |
Collaborator
There was a problem hiding this comment.
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 FalseAnd use this to filter out the SpacyRecognizer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change Description
SlimSpacyNlpEnginedisables NER, but the recognizer registry treated it like a regular spaCy engine and addedSpacyRecognizer.When
SpacyRecognizerreceived 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
SlimSpacyNlpEngineis used, the registry no longer addsSpacyRecognizerautomatically.If
SpacyRecognizeris 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