Test Severity: Warn vs Error
By default, if a single row fails a dbt test, the test is marked as an ERROR.
When using dbt build (which runs models and tests in topological order), an ERROR is fatal. It instantly halts that branch of the DAG. The failed model will not be deployed, and all downstream models that depend on it will be skipped.
This strict behavior is excellent for critical columns like Primary Keys. But what about a column like customer_phone_number? If your Indian e-commerce app has 10 million customers, and 3 customers accidentally have a NULL phone number, do you really want to crash the entire nightly data pipeline and delay the CEO's revenue report?
Probably not. For non-fatal data quality issues, we use Test Severity.
Topics Covered
- Warn vs Error behavior
- Configuring Severity (Global vs Specific)
- Setting Thresholds (e.g., Error if > 50 failures)
1. Warn vs Error Behavior
dbt supports two severity levels:
error(Default): If 1 or more rows fail, print a red message in the terminal. Halt the DAG. Skip downstream models. Return a non-zero exit code (failing the CI/CD pipeline).warn: If 1 or more rows fail, print a yellow message in the terminal. Continue executing the DAG. Downstream models will still build. Return a zero exit code (CI/CD pipeline passes).
2. Configuring Severity
To change the severity of a test, we convert the simple test definition into a dictionary and add a config: block.
Example: Making a test non-fatal
Let's apply a warning severity to the phone_number column.
models:
- name: dim_customers
columns:
- name: customer_id
description: "Primary key. Must be strictly tested."
tests:
- unique
- not_null
- name: phone_number
description: "Customer contact number. Nulls are bad, but not pipeline-breaking."
tests:
- not_null:
config:
severity: warn
When you run dbt build, and it finds 3 rows with a NULL phone number, it will print a yellow warning to the console, and then smoothly continue to build the downstream fct_orders table.
3. Setting Thresholds (Error vs Warn limits)
Sometimes, "Warn vs Error" is not a binary choice. It depends on the volume of the bad data.
If 3 out of 10 million phone numbers are NULL, that's a Warning. But if a bug in the source application causes 50,000 phone numbers to be NULL today, that is a massive crisis, and the pipeline should throw an Error!
You can configure exact integer thresholds using error_if and warn_if.
models:
- name: dim_customers
columns:
- name: phone_number
tests:
- not_null:
config:
# If there are between 1 and 49 nulls, throw a WARNING.
warn_if: ">0"
# If there are 50 or more nulls, throw an ERROR and crash the DAG!
error_if: ">49"
This threshold logic is incredibly powerful for monitoring Data Drift and identifying systemic failures in third-party APIs.
4. Project-Level Global Overrides
In some testing or staging environments, Data Engineers might want to run the entire pipeline even if tests fail, just to see what the final output looks like.
You can globally override test severity using the dbt CLI by passing a --warn-error flag (to make all warnings fatal) or by using project variables to globally set everything to warn. However, the standard practice is to configure severity precisely at the column level in your YAML files.
Summary
- ERROR is the default severity. It is fatal, crashes the DAG, and skips downstream models.
- WARN severity prints a yellow message but allows the pipeline to continue successfully.
- Use
warnfor non-critical columns where slight data corruption is acceptable over delaying reports. - Use
warn_ifanderror_ifthresholds to dynamically escalate warnings into errors based on the total number of failing rows.