Skip to content

rdt-model-policy

rdt-model-policy is the DQ rule compiler. It manages a shared library of CEL-based validation rules and compiles them to multiple execution targets: dbt tests (batch enforcement at scale via dbt Cloud) and Snowflake UDFs (interactive single-value validation from steward UI).

Rules are defined once in rules/library/ using CEL (Common Expression Language) and bound to entity properties via models/{entity}/rules.yaml. See ADR 0013 and the DQ Rule Library reference for the full design.

Pipeline phase: Phase 4 — Deploy

Compiles entity bindings into dbt tests and Snowflake UDFs. If model.json exists for the entity, binding properties are validated against model fields first (fail-early on unknown columns).

Terminal window
rdt-model-policy --target dev --entity <name> compile
rdt-model-policy --target dev --entity <name> compile --granular-tests
rdt-model-policy --target dev --entity <name> --dry-run compile
FlagEffect
--granular-testsOne file per rule instead of combined dq_all_rules.sql

Output:

FileFormatDescription
dbt/tests/{entity}/dq_all_rules.sqlSQLCombined dbt test — UNION ALL across all rules (default)
dbt/tests/{entity}/dq_{rule_id}.sqlSQLPer-rule dbt test (with --granular-tests)
snowflake/udf/dq_{rule_id}.sqlSQLSnowflake UDF DDL (Python for Tier 1, SQL for Tier 2+)

Regenerates rules/registry.yaml — the searchable index of all rules in the library. Includes SHA-256 content hashes for duplicate detection.

Terminal window
rdt-model-policy --target dev catalog
rdt-model-policy --target dev catalog --strict
FlagEffect
--strictExit non-zero if duplicate CEL expressions are detected across rules

Cross-references binding properties against entity model fields. Catches references to non-existent columns before they cause dbt runtime failures.

Terminal window
rdt-model-policy --target dev --entity <name> validate-bindings

Comparison is case-insensitive (model fields are UPPER_CASE SQL names, bindings use lowercase targeting the Silver view).

Evaluates a single rule against a JSON value locally using cel-interpreter. Tier 1 only (Tier 2+ requires Snowflake connectivity).

Terminal window
rdt-model-policy --target dev eval-rule --rule valid-roche-email --value '{"email":"user@roche.com"}'

Output:

{
"rule_id": "valid-roche-email",
"passed": true,
"message": ""
}

Tests a rule against a fixture file with multiple test cases.

Terminal window
rdt-model-policy --target dev test-rule --rule positive-number --fixtures rules/fixtures/positive-number-test.json

Fixture format:

{
"cases": [
{"input": {"amount": 42}, "expected": true},
{"input": {"amount": -1}, "expected": false}
]
}
KeySourceDescription
rules/library/RepositoryShared rule definitions (CEL YAML)
models/{entity}/rules.yamlRepositoryEntity-specific rule bindings
rules/registry.yamlGeneratedAuto-generated rule catalog
  • rules/library/ — shared DQ rule definitions
  • models/{entity}/rules.yaml — entity bindings (new format, references library rules)

Policy compilation flow — CEL rules compiled to dbt tests and Snowflake UDFs