Skip to content

fix(structured): default tabular entity selection to the mixed strategy (#1316) - #2261

Open
developer-rpai wants to merge 1 commit into
data-privacy-stack:mainfrom
developer-rpai:fix-structured-default-strategy-1316
Open

developer-rpai wants to merge 1 commit into
data-privacy-stack:mainfrom
developer-rpai:fix-structured-default-strategy-1316

Conversation

@developer-rpai

Copy link
Copy Markdown

Problem

PandasAnalysisBuilder.generate_analysis defaulted to the most_common entity selection strategy, which counts raw detections per entity type and ignores their confidence scores. A column of email addresses is a concrete casualty: john.doe@example.com yields one EMAIL_ADDRESS at 1.0, but the URL recognizer also fires on the domain part, so six URL detections at 0.5 outvote three EMAIL_ADDRESS detections at 1.0 and the column is misidentified as URL. The resulting StructuredAnalysis(entity_mapping={'email': 'URL', ...}) then drives the wrong anonymization for that column.

Fixes #1316.

Fix

Default the selection strategy to mixed: the entity with the highest confidence is selected when its score exceeds mixed_strategy_threshold (default 0.5); otherwise selection falls back to the most common entity — the combination proposed in the issue thread. Behavior is unchanged wherever no detection is confident (the fallback is exactly the old default), and most_common / highest_confidence remain available explicitly.

Behavior change

generate_analysis() without an explicit selection_strategy may now return a different entity for a column when at least one detection exceeds the mixed threshold. Docs (docs/structured/index.md) updated to mark Mixed as the default.

Tests

  • Added test_generate_analysis_tabular_default_strategy_detects_email_address (presidio-structured misidentifies email as URL #1316 regression test): asserts the default analysis maps email -> EMAIL_ADDRESS on the issue's data.
  • Verified the new test fails on the pre-fix code (maps to URL) and passes with the fix.
  • Full presidio-structured suite: 30 passed (en_core_web_lg).

…gy (data-privacy-stack#1316)

PandasAnalysisBuilder.generate_analysis defaulted to the most_common
selection strategy, which counts raw detections per entity type and
ignores their confidence scores. A column of email addresses was a
concrete casualty: john.doe@example.com yields EMAIL_ADDRESS at 1.0, but
the URL recognizer also fires on the domain part, so six URL hits at
0.5 outvoted three EMAIL_ADDRESS hits at 1.0 and the column was
misidentified as URL.

Default to the mixed strategy instead: the entity with the highest
confidence is selected when its score exceeds mixed_strategy_threshold
(0.5), otherwise selection falls back to the most common entity. This is
the combination proposed in the issue thread. most_common and
highest_confidence remain available explicitly.

Adds a regression test pinning the issue's data to EMAIL_ADDRESS under
the default, and marks Mixed as the default in the structured docs.
@github-actions github-actions Bot added documentation structured-data Handling structured/semi-structured data test external labels Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation external structured-data Handling structured/semi-structured data test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

presidio-structured misidentifies email as URL

1 participant