Skip to content

619 feature generate dqx rules from odcs data contracts#932

Merged
mwojtyczka merged 50 commits into
mainfrom
619-feature-generate-dqx-rules-from-odcs-data-contracts
Nov 21, 2025
Merged

619 feature generate dqx rules from odcs data contracts#932
mwojtyczka merged 50 commits into
mainfrom
619-feature-generate-dqx-rules-from-odcs-data-contracts

Conversation

@vb-dbrks

@vb-dbrks vb-dbrks commented Nov 14, 2025

Copy link
Copy Markdown
Contributor

Changes

Added support for generating DQ rules from ODCS (Open Data Contract Standard) v3.0.x data contracts. This enables customers implementing data contracts to automatically derive quality checks from their standardised contract definitions.

Key features:

  • Implicit rule generation: Automatically infers checks from schema properties (required, unique, pattern, minValue/maxValue, validValues, format)
  • Explicit rule generation: Supports custom DQX-native rules embedded in ODCS contracts
  • Text-based rules: Converts natural language quality expectations to DQX rules using LLM (optional)
  • Dataset-level rules: Supports both property-level and dataset-level quality checks (e.g., freshness, row counts)
  • Full validation: Validates contracts against official ODCS JSON schemas (v3.0.0-v3.0.2)
  • Lineage tracking: Preserves contract metadata (name, version, property, dimension) in generated rules

New components:

  • src/databricks/labs/dqx/datacontract/ - New module for contract parsing and rule generation
  • src/databricks/labs/dqx/datacontract/schemas/ - Bundled ODCS JSON schemas for validation
  • demos/dqx_demo_odcs.py - Interactive demo notebook
  • Added jsonschema dependency for contract validation

Usage:

generator = DQGenerator(workspace_client=ws)
rules = generator.generate_rules_from_contract(
    contract=odcs_contract_dict,
    generate_implicit_rules=True,
    process_text_rules=True,
    default_criticality="error"
)

Linked issues

Resolves #...

Tests

  • manually tested
  • added unit tests (30 test cases for parsing and rule generation)
  • added integration tests (8 end-to-end tests with Spark DataFrames)
  • added end-to-end tests
  • added performance tests

Adding support for automated rule generation from ODCS data contracts.

 ODCS (Open Data Contract
Standard) v3.0.x data contracts are supported. Rules can be generated implicitly from schema
properties (required fields, value ranges, patterns, formats) or explicitly
from quality definitions and text-based expectations!

Main entry point is DQGenerator.generate_rules_from_contract() which supports:
- Implicit rules from schema constraints (required, unique, min/max, pattern, etc)
- Explicit rules in DQX native format
- Text-based expectations processed via LLM with full schema context
- Custom criticality mapping by quality dimension
- Complete contract metadata tracking in generated rules

Includes unit tests, integration tests, demo notebook, and
sample contracts for testing and documentation.
…ity in explicit custom rules, so adding an external mapping parameter was redundant and complex.
…validation

- Enforce full JSON Schema validation against bundled ODCS schemas (v3.0.0, v3.0.1, v3.0.2)
- Implement proper ODCS quality check format with required fields:
  * type: "text" or "custom" (required)
  * engine: "dqx" for custom checks (required)
  * implementation: contains DQX rule details (required)
- Use ODCS-compliant logical types:
  * 'date' for both dates and timestamps (distinguished by format)
  * 'number' instead of 'numeric'
- Detect timestamps vs dates based on format string (HH, mm, ss)
- Extract DQX checks from 'implementation' field per ODCS custom format spec
@vb-dbrks vb-dbrks linked an issue Nov 14, 2025 that may be closed by this pull request
1 task
@vb-dbrks vb-dbrks marked this pull request as ready for review November 17, 2025 16:27
@vb-dbrks vb-dbrks requested a review from a team as a code owner November 17, 2025 16:27
@vb-dbrks vb-dbrks requested review from tombonfert and removed request for a team November 17, 2025 16:27
@vb-dbrks vb-dbrks added documentation Improvements or additions to documentation enhancement New feature or request dependencies Pull requests that update a dependency file labels Nov 17, 2025
Comment thread demos/dqx_demo_datacontract_odcs.py Outdated
Comment thread demos/dqx_demo_datacontract_odcs.py Outdated
Comment thread demos/dqx_demo_datacontract_odcs.py Outdated
Comment thread demos/dqx_demo_datacontract_odcs.py
Comment thread docs/dqx/docs/guide/data_contract_quality_rules_generation.mdx Outdated
Comment thread docs/dqx/docs/guide/data_contract_quality_rules_generation.mdx Outdated
Comment thread docs/dqx/docs/installation.mdx
Comment thread tests/integration/test_datacontract_integration.py Outdated

Copilot AI 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.

Pull Request Overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 9 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/unit/test_datacontract_utils.py Outdated
Comment thread tests/unit/test_datacontract_utils.py Outdated
Comment thread src/databricks/labs/dqx/datacontract/contract_rules_generator.py Outdated
Comment thread src/databricks/labs/dqx/datacontract/contract_rules_generator.py Outdated
Comment thread docs/dqx/docs/guide/data_contract_quality_rules_generation.mdx Outdated
Comment thread docs/dqx/docs/guide/data_contract_quality_rules_generation.mdx Outdated
Comment thread docs/dqx/docs/guide/data_contract_quality_rules_generation.mdx Outdated
Comment thread docs/dqx/docs/guide/data_contract_quality_rules_generation.mdx Outdated
Comment thread demos/dqx_demo_datacontract_odcs.py Outdated

Copilot AI 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.

Pull Request Overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/databricks/labs/dqx/profiler/generator.py
Comment thread tests/unit/test_datacontract_utils.py Outdated
Comment thread tests/unit/test_datacontract_generator.py Outdated
Comment thread src/databricks/labs/dqx/datacontract/contract_rules_generator.py Outdated
Comment thread src/databricks/labs/dqx/datacontract/contract_rules_generator.py Outdated
Comment thread pyproject.toml
Comment thread src/databricks/labs/dqx/datacontract/contract_rules_generator.py
Comment thread tests/resources/sample_datacontract_old.yaml 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

Comment thread tests/integration/test_datacontract_integration.py Outdated
Comment thread src/databricks/labs/dqx/datacontract/contract_rules_generator.py Outdated
Comment thread src/databricks/labs/dqx/datacontract/contract_rules_generator.py Outdated

Copilot AI 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.

Pull Request Overview

Copilot reviewed 17 out of 19 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/databricks/labs/dqx/utils.py
@mwojtyczka mwojtyczka mentioned this pull request Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Generate DQX rules from ODCS data contracts

3 participants