sverify-dbt
Sverify-dbt is a working prototype, and so is sverify, which it builds on. Their proofs and code still need a human audit before anyone relies on their results.
Sverify-dbt proves a dbt project's data tests and model contracts before
the models run. It reads the project after dbt compile, checks each
model's compiled SQL with sverify against the tests on
the models and sources it reads, and reports per model which tests hold on
every run, which may fail and why, and which source tests would let it prove
more. A test it proves can be left out of dbt build: it rests on
contract_sound and Rel.keys_sound, applied to the model's compiled SQL
under semantics="duckdb" (proofs.md).
It reads DuckDB projects (dbt-duckdb). The other adapters wait on sverify's other engines, which don't run every function DuckDB does yet.
Installation
Sverify-dbt is published with sverify, at the same version, from substrait-lean's releases on:
# skip: installs software on the reader's machine
pip install sverify-dbt dbt-duckdb
Usage
Compile the project, then check it:
# skip: needs a dbt project
dbt docs generate # writes target/catalog.json, where the column types come from
dbt compile --full-refresh # also after a `dbt run`: a plain compile renders `{{ this }}`
sverify-dbt check .
Without the catalog, sverify-dbt takes types from each column's data_type
in the YAML. A seed has types in the catalog once dbt seed has loaded it and
dbt docs generate has run. It refuses a model whose inputs have none. After a dbt run, a plain dbt compile
renders each incremental model's is_incremental() branch, which reads
{{ this }}; sverify-dbt refuses it and asks for dbt compile --full-refresh.
On the sample project in examples/shop:
stg_orders (models/staging/stg_orders.sql)
proved before the model runs (dbt build may skip them):
not_null(order_id)
unique(order_id)
not_null(customer_id)
accepted_values(status)
dbt_utils.accepted_range(amount)
customer_revenue_by_category (models/marts/customer_revenue_by_category.sql)
proved before the model runs (dbt build may skip them):
dbt_utils.accepted_range(books)
contract: columns and types match
primary_key(customer_id): proved
note: rows may tie in an ORDER BY of a window or ordered aggregate, so DuckDB picks the order: a test that depends on it is not proved
orders_with_city (models/marts/orders_with_city.sql)
proved before the model runs (dbt build may skip them):
not_null(order_id)
unique(order_id)
org_depth (models/marts/org_depth.sql)
refused: sverify cannot read WITH RECURSIVE yet (#320)
subscription_arr (models/marts/subscription_arr.sql)
proved before the model runs (dbt build may skip them):
dbt_utils.accepted_range(arr)
--selectors adds a selector, sverify_proved, to the project's
selectors.yml (keeping the others), and dbt build skips the tests it
selects:
# skip: needs a dbt project
sverify-dbt check . --selectors
dbt build --exclude selector:sverify_proved
sverify-dbt suggest prints the tests that would let sverify prove more,
as a dbt properties file to merge into the project's YAML: what each model
needs, and the tests on its inputs under which an unproved test would hold,
each with its reason as a comment (--output FILE writes it). Where a NULL comes through an expression of the model, such as cast(ordered_at as date), it also tries not_null on the columns of the inputs that no test covers, and names the ones the proof needs. Merge them
by hand, and tighten a bound where your data allows:
examples/shop/PROOF-STATUS.md shows one.
# skip: needs a dbt project
sverify-dbt suggest .
The other options of check:
| Option | What it does |
|---|---|
--select MODEL ... |
Report on these models (their upstream models are checked too); not with --selectors, which needs the whole project |
--format text|json|github|sarif|junit |
How to print the result (default text): github is one annotation per finding on the model's file, sarif a code-scanning log, junit a suite per model; sverify check forwards its own |
--timeout SECONDS |
Seconds for the whole project check (default $SVERIFY_TIMEOUT, else no limit); exit 5 past it |
--memory-limit SIZE |
DuckDB's memory limit, such as 2GB (default $SVERIFY_MEMORY_LIMIT); exit 5 past it |
--json |
Print the result as JSON (--format json): the document of sverify check --format json (cli.schema.json), with each model as an item and findings, exit, status, adapter and dbt_version beside the project's own keys |
--counterexamples N |
Small inputs to try per unproved test (default 200; 0 skips the search) |
--fail-on |
Exit 1 on a contract mismatch, an unproved constraint, or a refused model with an enforced contract, whose contract sverify could not check (contract, the default; stderr names the refusal); unproved: also on any unproved test; refused: all of that, and exit 3 when a model was refused (sverify cannot read it); never |
--target-path |
The target directory, if not target |
Exit codes, as in sverify check: 0 holds, 1 something is not proved, 2 usage (no manifest, an unknown model, another adapter), 3 a model is refused under --fail-on refused or the check is unsupported, 5 past --timeout or --memory-limit, 8 an error (the checker is missing, an I/O failure) with its message on stderr. The codes run from the best to the worst (sverify.cli.ExitCode).
The same from Python:
# skip: needs a compiled dbt project at path/to/project
import sverify_dbt
result = sverify_dbt.check("path/to/project")
print(result)
result["stg_orders"].by_status("proved")
result.write_selectors("path/to/project/selectors.yml")
The agent skill sverify-patterns (in sverify/skills/) has the SQL form of common patterns with the contract each proves: deduplicating, sessionizing, reconciling, funnels, slowly changing dimensions, running balances and gap filling. Each SQL form runs through sv.sql as a dbt model's body does.
How a project becomes contracts
Each model is checked on its own, the way dbt builds it. Its compiled SQL is
sverify.verify's query, under DuckDB's semantics (semantics="duckdb"),
over its refs and sources. Their column types come from
target/catalog.json when dbt docs generate wrote one, else from the
data_types in the YAML (a seed's column_types among them), and for a
model from DuckDB's types for its SQL.
- The tests on what a model reads are its preconditions (
requires).dbt buildruns them first and skips the models downstream of a failure, so they hold whenever the model runs. A test with severitywarn, or thresholds (error_if,fail_calc), lets the build go on, and counts only once it is proved. - The model's own tests are its postconditions (
ensures). A proved test holds on every run whose inputs pass their tests. - An enforced contract (
contract: {enforced: true}) is checked too: its columns and types against the model's result, and its constraints (not_null,unique,primary_key,check) as postconditions, before dbt's own check at build time.
Only tests carry from one model to the next. A key that sverify proves of a model's result, but that no test states, is unknown to the models downstream; add the test and it carries.
The tests sverify-dbt reads:
| Test | Condition on each row |
|---|---|
not_null, dbt_expectations.expect_column_values_to_not_be_null |
c IS NOT NULL |
accepted_values, dbt_expectations.expect_column_values_to_be_in_set |
c IS NULL OR c IN (...) |
dbt_expectations.expect_column_values_to_not_be_in_set |
c IS NULL OR c NOT IN (...) |
dbt_utils.accepted_range, dbt_expectations.expect_column_values_to_be_between |
c IS NULL OR (c >= min AND c <= max), strict where the test says |
dbt_utils.not_accepted_values |
c IS NULL OR c NOT IN (...) |
dbt_utils.not_empty_string |
c IS NULL OR trim(c) <> '' |
dbt_expectations.expect_column_values_to_[not_]match_regex[_list] |
c IS NULL OR regexp_matches(c, re), joined by match_on (any or all) |
dbt_expectations.expect_column_values_to_[not_]match_like_pattern[_list] |
c IS NULL OR c LIKE p, joined by match_on |
dbt_expectations.expect_column_value_lengths_to_equal, …_to_be_between |
c IS NULL OR length(c) … |
dbt_expectations.expect_column_pair_values_A_to_be_greater_than_B, …_values_to_be_equal |
coalesce(A > B, TRUE), coalesce(A = B, TRUE) |
dbt_utils.expression_is_true |
coalesce(expression, TRUE) |
unique, dbt_expectations.expect_column_values_to_be_unique |
a key (sv.unique) |
dbt_utils.unique_combination_of_columns, dbt_expectations.expect_compound_columns_to_be_unique |
a key over the columns |
relationships |
a foreign key (sv.references), as a precondition only |
NULLs pass each test, as they do in dbt. A test's where config and
dbt-expectations' row_condition limit the condition to the rows they keep.
dbt's unique lets NULLs repeat while a key counts them as one value, so a
unique test is a precondition only on a column a not_null test covers too.
When the proof needs a precondition no test states, such as a bound that
rules out an overflow, the model's tests stay unproved and the report lists
the test to add under needs, as YAML for the input's column (sverify's
Report.needs).
Limits
- Generic data tests only. Singular tests and unit tests (
given/expect) are listed as not checked. - A model is refused where sverify cannot read its SQL (
WITH RECURSIVE), with the construct named, and where it reads a table that is noreforsource. - Sverify tracks a column's strings while they are few (up to 64), from
constants,
INlists,=and<>filters,CASE,COALESCEandUNION ALL, which provesaccepted_valuesthere; what is inside a string (LIKE, regexes, lengths) is not tracked, so those tests are proved where the same test holds upstream and the column passes through (the guide). Sverify reads no regex flags, so a regex test withflagsis not checked. - Python models, and models whose inputs have no column types, are refused.
- What each materialization gets: a table or view is checked; an incremental model as its full refresh (below); an ephemeral model is inlined, so its readers are read through it and it prints a note, with no test run on it; a snapshot is an input only. Python models are refused.
- An incremental model is checked as its full refresh, as
dbt compilerenders it; itsis_incremental()block is taken to only filter that query. Its tests are skippable (--selectors) only undermergeordelete+inserton aunique_keythat a proveduniquetest names, and then only the row-level tests (not_null,accepted_values,accepted_range,expression_is_true) anduniqueover that key or more columns: other proved tests are listed as proved for the full refresh, anddbt buildstill runs them.
Evidence
python -m sverify_dbt.replay builds the integration projects of
dbt-utils 1.4.1 and dbt-expectations 0.10.10, the projects of the pytest
classes in dbt-tests-adapter 1.20.0, and those of dbt-core v1.12.6's
functional tests with tests or contracts (constraints, contracts, data tests,
incremental schema tests, primary keys, schema tests, sources), with dbt on
DuckDB. It checks them with sverify-dbt and records every test, and every
constraint of an enforced contract, beside dbt's own result, in
replay/ (#859). No test sverify-dbt proves fails in dbt's run.
| Source | Proved | Not proved | Not checked | Refused | Inputs |
|---|---|---|---|---|---|
| dbt-utils 1.4.1 | 3 | 13 | 46 | 14 | 37 |
| dbt-expectations 0.10.10 | 0 | 33 | 9 | 115 | 0 |
| dbt-tests-adapter 1.20.0 | 37 | 11 | 98 | 10 | 13 |
| dbt-core v1.12.6 | 22 | 12 | 38 | 35 | 3 |
These projects test macros more than they model data: most of their tests
compare two relations or match patterns with flags, which sverify-dbt leaves
to dbt by design, and most of dbt-expectations' models cast to float32,
which Lean's model does not cover
(#417),
or use random(). Every refusal and test not checked names its issue or the
reason it is by design (replay/constructs.json).
dbt-core's refusals are mostly tables its suite creates outside dbt, which no
ref() or source() names. The suites' classes whose fixtures need a running
warehouse, abstract bases a subclass fills in, and the projects dbt cannot
build are listed under unextracted in each ledger. CI's dbt job replays
them: a changed outcome warns, and a test sverify-dbt proves that fails in
dbt's own run fails the job.
Development
# skip: builds or tests the repository, which needs elan and takes minutes
cd dbt
uv sync
uv run pytest
uv sync installs the sverify of this checkout (../python), with the
checker its build hook links or builds.
The tests compile the sample project and a few small ones with dbt's own
runner. CI runs them, then the check of examples/shop, and dbt build
without the proved tests (the dbt job of
ci.yml). API-NOTES.md lists
what building on sverify's public API showed.
Metadata
Release files for sverify-dbt 0.9.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sverify_dbt-0.9.0.tar.gz | 237.6 kB | With provenance | Details for sverify_dbt-0.9.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sverify_dbt-0.9.0-py3-none-any.whl | Python 3 | none | any | Details for sverify_dbt-0.9.0-py3-none-any.whl |
Total release size: 285.2 kB
Release files / sverify_dbt-0.9.0.tar.gz
| Download URL | sverify_dbt-0.9.0.tar.gz |
|---|---|
| Size | 237.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
385b90c4bf56729b81fa48df135e61171105a2c16aa51e836bb937292dae9374
|
|
BLAKE2b-256 checksum How to use checksums |
9e99a514bbf1b216e99dfa7dffb09753216316db0127067d50388459d15e77ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logRelease files / sverify_dbt-0.9.0-py3-none-any.whl
| Download URL | sverify_dbt-0.9.0-py3-none-any.whl |
|---|---|
| Size | 47.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
26a4b1e1cc5a62b231003ac01d648f45a68c9c1b270ead64fd908a7ac10eb642
|
|
BLAKE2b-256 checksum How to use checksums |
27ccadf8ecabab6df9f6d1efd67ed6384156531eee7b5e4fd14874da37a47265
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logSecurity for sverify-dbt 0.9.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for sverify_dbt-0.9.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.