For data tests!
Tests return a number of failures—most often, this is the count of rows returned by the test query, but it could be a custom calculation. Generally, if the number of failures is nonzero, the test returns an error. This makes sense, as test queries are designed to return all the rows you don't want: duplicate records, null values, etc.
It's possible to configure tests to return warnings instead of errors, or to make the test status conditional on the number of failures returned. Maybe 1 duplicate record can count as a warning, but 10 duplicate records should count as an error.
The relevant configs are:
Config | Description | Default |
---|---|---|
severity |
error or warn |
error |
error_if |
Conditional expression | !=0 |
warn_if |
Conditional expression | !=0 |
Conditional expressions can be any comparison logic that is supported by your SQL syntax with an integer number of failures:
> 5, = 0, between 5 and 10, and so on.
If severity: error
, dbt will check the error_if
condition first. If the error condition is met, the test returns an error. If it's not met, dbt will then check the warn_if
condition (defaulted to !=0
). If it's not specified or the warn condition is met, the test warns; if it's not met, the test passes.
If severity: warn
, dbt will skip the error_if
condition entirely and jump straight to the warn_if
condition. If the warn condition is met, the test warns; if it's not met, the test passes.
By default, a test with severity: warn
will only ever return a warning, and not cause errors. However, you can promote warnings to errors using:
--warn-error
: Promotes all dbt warnings (including test warnings, Jinja warnings, deprecations, and so on.) to errors.
--warn-error-options
: Promotes only specific types of warnings.
models/.yml
version:2
models:
-name:large_table
columns:
-name:slightly_unreliable_columndata_tests:
-unique:config:
severity:errorerror_if:">1000"warn_if:">10"
tests/.sql
{{ config(error_if='>50')}}
select...
macros/.sql
{%test(model,column_name)%}{{ config(severity='warn')}}
select...
{%endtest%}
dbt_project.yml
data_tests:
+:severity:warn # all tests
:
+:warn_if:">10" # tests in
Create a GitHub issue
Edit this page
Last updated on Aug 29, 2025