context_columns parameter.
When a test fails, the failing rows are returned together with the columns you care about — making it much easier to investigate the root cause directly from the test results.
If context_columns is omitted, all columns are returned alongside failing rows.
A single column can be given as a plain string instead of a list.
No extra packages are required. These tests ship with the Elementary dbt
package and do not depend on
dbt_utils or dbt_expectations being installed,
even where they mirror a test from one of those packages.If a column listed in
context_columns does not exist on the model, a warning
is logged and that column is skipped. The test continues and will not error.To test only some of the rows, use dbt’s
where config.
Earlier versions of some of these tests took a row_condition argument
instead; it was removed in favour of where, which does the same thing and
works on every dbt test.not_null_with_context
elementary.not_null_with_context
Validates that there are no null values in a column. Extends dbt’s built-in not_null test.
Parameters
expression_is_true_with_context
elementary.expression_is_true_with_context
Validates that a SQL expression holds for every row. Extends dbt_utils.expression_is_true.
This is the most flexible test in the set: any condition you can write in SQL, including range checks and comparisons across columns.
This test is table-level, so it has no tested column of its own. List every
column you want in the sample under
context_columns, including the ones your
expression references.Parameters
not_empty_string_with_context
elementary.not_empty_string_with_context
Validates that a column contains no empty strings. Extends dbt_utils.not_empty_string.
Parameters
expect_column_values_to_not_be_null_with_context
elementary.expect_column_values_to_not_be_null_with_context
Expects column values to not be null. Extends dbt_expectations.expect_column_values_to_not_be_null.
Parameters
expect_column_values_to_be_unique_with_context
elementary.expect_column_values_to_be_unique_with_context
Expects column values to be unique. Returns all duplicate rows (not just a count), so you can see the full context of each duplicate. Extends dbt_expectations.expect_column_values_to_be_unique.
Null values are ignored rather than treated as duplicates of one another, matching dbt’s built-in unique test.
Parameters
expect_compound_columns_to_be_unique_with_context
elementary.expect_compound_columns_to_be_unique_with_context
Expects a combination of columns to be unique. Returns every duplicate row, so you can see the full context of each collision. Extends dbt_expectations.expect_compound_columns_to_be_unique.
Rows where every listed column is null are ignored rather than treated as duplicates of one another.
Use this when no single column identifies a row, for example when uniqueness is on a customer and date pair.
Parameters
expect_column_pair_values_A_to_be_greater_than_B_with_context
elementary.expect_column_pair_values_A_to_be_greater_than_B_with_context
Expects the values of one column to be greater than another. Extends dbt_expectations.expect_column_pair_values_A_to_be_greater_than_B.
Both compared columns are always returned with failing rows, before any context_columns.
Parameters
expect_column_values_to_match_regex_with_context
elementary.expect_column_values_to_match_regex_with_context
Expects column values to match a given regular expression. Extends dbt_expectations.expect_column_values_to_match_regex.
Parameters
expect_column_values_to_match_regex_list_with_context
elementary.expect_column_values_to_match_regex_list_with_context
Expects column values to match any or all of a list of regular expressions. Extends dbt_expectations.expect_column_values_to_match_regex_list.
Parameters
relationships_with_context
elementary.relationships_with_context
Validates referential integrity between a child and parent table. Extends dbt’s built-in relationships test.
Parameters
accepted_range_with_context
elementary.accepted_range_with_context
dbt_utils.accepted_range selects every column already, so unlike the other
tests on this page this one cannot add context to a stored sample. The only
thing it can do is narrow the sample to a chosen subset, which is not what
context_columns is for.
If you were using it to keep columns out of a stored sample, there is no direct
replacement. Use the sampling controls instead: the show_sample_rows and PII
tags, disable_test_samples, or test_sample_row_count.
Migration
Before
After

