OpenMetadata icon indicating copy to clipboard operation
OpenMetadata copied to clipboard

Auto-classification: one custom recognizer with an invalid regex drops every tag on the column

Open vamsibvv opened this issue 1 month ago • 0 comments

Affected module

Ingestion Framework

Describe the bug

A custom recognizer that Presidio cannot build or compile makes auto-classification fail for every column it runs on, and the other tags scored for those columns are lost with it. All of these configs are accepted by the schema:

  • a pattern recognizer with an invalid regex, e.g. EMP-(\d{6}
  • a pattern recognizer with no patterns (patterns defaults to []), which Presidio rejects with ValueError
  • a context recognizer whose context words contain regex characters, e.g. id (internal

Presidio compiles patterns on first use, so the error is raised from analyzer.analyze inside TagScorer.predict_scores. That aborts scoring for the whole column, AutoClassificationProcessor._run records the column as failed, and it gets no tags at all, including PII.Sensitive.

Context words are also put into the regex unescaped, so c++ and id (internal) never match and a.k.a matches aXkXa smith. In the same function, minScore: 0 is treated as unset (if config.minScore and config.maxScore), so minScore: 0, maxScore: 0.4 gives the pattern a score of 0.6.

To Reproduce

from unittest.mock import Mock
from presidio_analyzer.nlp_engine import NlpEngine
from metadata.pii.algorithms.tag_scoring import ScoreTagsForColumnService

# email_tag: PII.Sensitive with an email pattern recognizer
# badge_tag: Custom.Badge with one pattern recognizer, regex "EMP-(\d{6}"
# column: a STRING column with a fullyQualifiedName
service = ScoreTagsForColumnService(nlp_engine=Mock(spec=NlpEngine))
emails = [f"user{i}@example.com" for i in range(20)]

service(column, emails, [email_tag])             # [PII.Sensitive, score 0.9]
service(column, emails, [email_tag, badge_tag])  # regex error: missing ) at position 10

A context recognizer with the context word id (internal fails the same way (missing ) at position 49), and a pattern recognizer with patterns: [] raises ValueError: Pattern recognizer should be initialized with patterns or with deny list.

Expected behavior

The broken recognizer is skipped with an error log, and the other tags are still scored. Context words are matched literally, and minScore: 0 is respected.

OS

Ubuntu 24.04

Python version

3.12.3

OpenMetadata version

main (d42dff5)

OpenMetadata Ingestion package version

main

Additional context

I have a fix with tests: compile the patterns when the pattern recognizer is built and skip it with an error log if that or Presidio's constructor fails, escape context words, and compare minScore/maxScore to None. Happy to open a PR.

This is different from #34972 and #34824, which cover definitions that fail to parse. These parse fine and fail later, during analysis.

Pre-submission checklist

  • [x] I searched for duplicate issues.
  • [x] I removed credentials, hostnames, emails, and other sensitive data from logs and config.

vamsibvv avatar Oct 27 '26 08:10 vamsibvv