Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Assertions

Block bad data at materialization. Audits define the rule; assertions attach it to a model and stop the run if it fails.

An assertion is the blocking layer of the contract. It runs every time a model materializes, and if it finds bad data, Vulcan stops the run. Nothing bad reaches a consumer. Where a DQ check watches data and warns, an assertion blocks it.

Two terms travel together here, and they don't mean the same thing:

  • Audit - the validation rule itself: a named SQL query in audits/*.sql that returns rows when data is bad.

  • Assertion - the attachment of a rule to a model: a declaration inside the MODEL(...) block saying the model must pass that rule.

In short: audits define, assertions attach. A model's assertions(...) block can attach built-in functions (no SQL needed) or named audits you wrote yourself. Both block the run when they fail. audits(...) is an accepted alias for assertions(...) on the MODEL block. Both work identically; this guide uses assertions.

How it runs

An assertion passes when its query returns zero rows. Any row it returns counts as a failing row. For every model run:

  1. Vulcan evaluates the model SQL and inserts the data.

  2. It runs each attached assertion against the new data.

  3. If any assertion returns rows, execution stops and Vulcan reports the failure.

  4. If every assertion returns zero rows, execution continues and downstream models build on the new data. With vde: true, a plan then promotes the new version.

Inline assertions (start here)

The fastest way to add a check is a built-in function in the MODEL block's assertions property. You don't need a SQL file:

MODEL (
  name silver.fct_daily_sales,
  kind FULL,
  grains (order_date, region_id, customer_id, product_id),
  assertions (
    not_null(columns := (order_date, total_revenue)),
    unique_combination_of_columns(columns := (order_date, region_id, customer_id, product_id)),
    accepted_range(column := total_revenue, min_v := 0)
  )
);

Common built-in functions:

Category
Functions

Null and rows

not_null, at_least_one, not_null_proportion, number_of_rows

Uniqueness

unique_values, unique_combination_of_columns

Value

accepted_values, not_accepted_values, accepted_range, not_constant, forall, sequential_values

String

not_empty_string, string_length_between, valid_uuid, valid_email, valid_url

Statistical

mean_in_range, z_score

forall(criteria := (price > 0, LENGTH(name) > 0)) is the escape hatch: it accepts any boolean SQL expression.

Custom audits

When a built-in function can't express the rule, write a custom audit: a .sql file in audits/ that returns the offending rows. orders-analytics has 3, each attached to a model as an assertion, which is what makes it blocking. This one checks that the derived metrics in silver.fct_daily_sales are internally consistent:

@this_model refers to the model the audit is attached to. For incremental models, Vulcan adds an automatic time-range filter, so the audit only checks the interval that just ran.

Attach the audit by naming it in the model's assertions block, alongside any built-in functions:

A custom audit is reusable: define it once, attach it to any model. The orders-analytics audits also validate recency, frequency, and monetary (RFM) scores, and check referential integrity against the order-status seed.

For parameterized audits, global assertions via model_defaults, and more patterns, see References → Vulcan → Quality → Assertions.

Plan versus run

Command
On failure

vulcan plan

With vde: true, production is untouched: the bad data stays in the isolated snapshot table. With the default vde: false, a plan writes to the original tables, so the bad rows can land there, as with run.

vulcan run

The model writes to the production table first, then the assertion runs. On failure, the run halts: the bad rows can land, but downstream models won't build on them.

Use vulcan plan for production changes; with vde: true, it catches the failure before bad data reaches production. Run audits manually with vulcan audit --start <date> --end <date>, adding --model <name> to audit a single model.

An assertion is your block against bad data reaching a consumer. To verify the model's logic is right in the first place, before any warehouse run happens, write a test.

Last updated

Was this helpful?