Skip to content

Add built-in methods for PII detection#486

Merged
mwojtyczka merged 73 commits into
mainfrom
pii_detection
Aug 13, 2025
Merged

Add built-in methods for PII detection#486
mwojtyczka merged 73 commits into
mainfrom
pii_detection

Conversation

@ghanse

@ghanse ghanse commented Jul 27, 2025

Copy link
Copy Markdown
Collaborator

Changes

This PR introduces the pii module which users can install to access built-in checks for Personally Identifiable Information (PII). These built-in checks use the Presidio framework.

Installation

Users install PII detection capabilities as an extras module with additional dependencies:

pip install databricks-labs-dqx[pii]

Usage

Users can define checks using a new built-in function, contains_pii.

from databricks.labs.dqx.rule import DQRowRule
from databricks.labs.dqx.pii.pii_detection_funcs import contains_pii

checks = [
    # PII detection check using stanford-deidentifier-base as a named entity recognizer
    DQRowRule(
        name="col_description_contains_pii",
        criticality="error",
        column="description",
        check_func=contains_pii
    ),    
]

Configuration

Users can configure the underlying model by passing parameters to contains_pii. This includes NLP entity recognition configuration which can be passed as a Python dictionary or as an NLPEngineConfig. In the future, we can add NLPEngineConfig values to support different named entity recognizers.

TO-DO:

  • Introduce methods to configure the underlying named entity recognizer
  • Add tests
  • Add documentation
  • Update demos to use the built-in check

Linked issues

Resolves #419

Tests

  • manually tested
  • added unit tests
  • added integration tests

@ghanse ghanse requested a review from a team as a code owner July 27, 2025 15:25
@ghanse ghanse requested review from nehamilak-db and removed request for a team July 27, 2025 15:25
@github-actions

github-actions Bot commented Jul 27, 2025

Copy link
Copy Markdown
Contributor

✅ 9/9 passed, 54m20s total

Running from acceptance #1730

Comment thread docs/dqx/docs/reference/quality_rules.mdx Outdated
Comment thread docs/dqx/docs/reference/quality_rules.mdx Outdated
Comment thread docs/dqx/docs/reference/quality_rules.mdx Outdated
Comment thread src/databricks/labs/dqx/pii/check_funcs.py Outdated
Comment thread src/databricks/labs/dqx/pii/check_funcs.py Outdated
Comment thread src/databricks/labs/dqx/pii/pii_detection_funcs.py Outdated
Comment thread tests/integration/test_row_checks.py Outdated

def test_contains_pii_fails_session_validation(spark):
"""
We restrict running `contains_pii` using Databricks Connect. Because tests are run

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

would be useful to have info why we cannot use databricks connect

Comment thread .github/workflows/nightly.yml
Comment thread tests/integration/test_row_checks.py Outdated

@mwojtyczka mwojtyczka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM - left minor comment. Will merge after testing.

Comment thread src/databricks/labs/dqx/pii/pii_detection_funcs.py Outdated

@mwojtyczka mwojtyczka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

func name needs to be updated

@mwojtyczka mwojtyczka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM - will merge after testing

Comment thread src/databricks/labs/dqx/pii/pii_detection_funcs.py Outdated
This was referenced Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Add PII detection check func to the built-in checks using extras

3 participants