Skip to content

Implement semantic rule validation for DQ rules (#1169)#1203

Merged
mwojtyczka merged 15 commits into
databrickslabs:mainfrom
Vsatyam013:feat/1169-semantic-validation
Jun 30, 2026
Merged

Implement semantic rule validation for DQ rules (#1169)#1203
mwojtyczka merged 15 commits into
databrickslabs:mainfrom
Vsatyam013:feat/1169-semantic-validation

Conversation

@Vsatyam013

@Vsatyam013 Vsatyam013 commented May 27, 2026

Copy link
Copy Markdown
Contributor

Changes

Implements ruleset-level semantic validation for DQ checks (issue #1169).

Adds a ChecksSemanticValidator (module checks_semantic_validator.py) that inspects a ruleset (declarative check metadata) and reports two classes of issue:

  • Duplicate rules — rules with the same function, arguments, criticality and filter.
  • Conflicting rules — rules targeting the same function and column(s) but with different arguments (e.g. two is_in_range checks on the same column with different thresholds).

Semantic validation is integrated into validate_checks, load_checks and save_checks via a new semantic_validation_mode parameter:

Mode Behavior
"warn" (default) Log a warning per issue and continue.
"fail" Raise a ValueError listing all issues.
None Skip semantic validation.

Duplicate and conflicting rules are not necessarily invalid (a duplicate is redundant; a conflict may be intentional), so the default mode only warns; use "fail" to enforce a clean ruleset in CI/CD.

Notes on the implementation:

  • Rule identity handles both the nested and flat check forms, the top-level and in-block filter, and for_each_column; column-list comparison is order-insensitive.
  • Rules using raw Spark SQL expressions (sql_expression) are not deeply inspected — only structured metadata is compared.
  • Semantic validation is best-effort: malformed checks never crash the validator (they are skipped/logged and reported by structural validation instead).

Linked issues

Resolves #1169

Tests

  • added unit tests
  • added integration tests (negative scenarios for validate_checks, load_checks and save_checks)

Documentation and Demos

  • added/updated demos
  • added/updated docs
  • added/updated agent skills

@CLAassistant

CLAassistant commented May 27, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

Copy link
Copy Markdown
Contributor

All commits in PR should be signed ('git commit -S ...'). See https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits

@Vsatyam013 Vsatyam013 force-pushed the feat/1169-semantic-validation branch from d9d5ef7 to 379a5ba Compare May 27, 2026 16:44
@Vsatyam013 Vsatyam013 marked this pull request as ready for review May 28, 2026 03:08
@Vsatyam013 Vsatyam013 requested a review from a team as a code owner May 28, 2026 03:08
@Vsatyam013 Vsatyam013 requested review from grusin-db and removed request for a team May 28, 2026 03:08
@Vsatyam013 Vsatyam013 force-pushed the feat/1169-semantic-validation branch from ff01ddc to f84132b Compare May 29, 2026 05:41
ghanse
ghanse previously requested changes Jun 2, 2026

@ghanse ghanse left a comment

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.

Hi @Vsatyam013 , the linked issue focuses more on validating the entire ruleset to detect the following issues:

  • Detect if a duplicate rule already exists with the same run config
  • Detect if a similar rule exists with different arguments (e.g. a narrower threshold of is_in_range)

Can you make some changes to address these more specifically? I think it should be simpler because the check function inputs are mostly structured. We can document any limitations when users execute checks with Spark expressions.

Comment thread CHANGELOG.md
Comment thread src/databricks/labs/dqx/checks_semantic_validator.py
@ghanse ghanse added under-review This PR is currently being reviewed by one of DQX maintainers. needs-changes Changes required after review labels Jun 2, 2026
@mwojtyczka

mwojtyczka commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

@Vsatyam013 do you plan to complete the PR, and address review comments? there was no update since 4 weeks.

@Vsatyam013 Vsatyam013 force-pushed the feat/1169-semantic-validation branch from ea0c092 to da2897a Compare June 25, 2026 03:24
@Vsatyam013

Vsatyam013 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Hi @mwojtyczka, sorry for the delay. I've reworked the implementation based on @ghanse's feedback. The SQL keyword validation approach has been removed and replaced with ruleset-level semantic checks, duplicate rule detection and conflicting rule detection (same function and column with different arguments). The validation is now integrated into validate_checks, save_checks, and load_checks with a configurable semantic_validation_mode parameter (warn, fail, or None). CHANGELOG changes have also been reverted.Can you review it?

Comment thread src/databricks/labs/dqx/engine.py Outdated
Comment thread src/databricks/labs/dqx/engine.py Outdated
Comment thread src/databricks/labs/dqx/engine.py Outdated
Comment thread src/databricks/labs/dqx/engine.py Outdated
Comment thread src/databricks/labs/dqx/engine.py Outdated
Comment thread src/databricks/labs/dqx/semantic_validator.py Outdated
Comment thread src/databricks/labs/dqx/engine.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.

Thank you for the PR. I feft some comments. The engine.py does not compile due to identation issues. Please also update the PR description.

- Fix IndentationError on load_checks/save_checks so the package compiles
- Use full-notation import; remove leftover marker comments and trailing
  whitespace in docstrings; drop backticks in docstrings per AGENTS.md
- Rename module to checks_semantic_validator and classes to
  ChecksSemanticValidator / ChecksSemanticValidationMode
- Fix unhashable-list crash in rule key by serializing arguments with json
- Harden helpers against malformed checks; handle mode=None in apply()
- Expose semantic_validation_mode on the public DQEngine.validate_checks
- Add negative integration tests for validate_checks, load_checks and
  save_checks (duplicate and conflicting rules)

Co-authored-by: Isaac

@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 - implemented feedback and increased code coverage

@mwojtyczka mwojtyczka requested a review from ghanse June 30, 2026 12:17
@mwojtyczka mwojtyczka changed the title feat: implement semantic rule validation for DQ rules (#1169) Implement semantic rule validation for DQ rules (#1169) Jun 30, 2026
@mwojtyczka mwojtyczka added Approved to Merge When PR is reviewed and approved. To be merged once all tests pass and removed under-review This PR is currently being reviewed by one of DQX maintainers. needs-changes Changes required after review labels Jun 30, 2026
@mwojtyczka mwojtyczka dismissed ghanse’s stale review June 30, 2026 16:03

requested changes implemented

@mwojtyczka mwojtyczka merged commit 7dcc54b into databrickslabs:main Jun 30, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved to Merge When PR is reviewed and approved. To be merged once all tests pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Add methods for semantic rule validation

4 participants