A set of generic tests that extend common dbt, dbt-utils, and dbt-expectations tests with a 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.
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.
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
Parameter Required Default Description column_nameYes — The column to test for null values. context_columnsNo noneList of additional columns to return with failing rows. Omit to return all columns.
With context columns
Return all columns
models :
- name : orders
columns :
- name : order_id
data_tests :
- elementary.not_null_with_context :
context_columns : [ customer_id , order_date , amount ]
accepted_range_with_context
elementary.accepted_range_with_context
Validates that column values fall within an accepted range. Extends dbt_utils.accepted_range.
Parameters
Parameter Required Default Description column_nameYes — The column to test. min_valueNo* noneMinimum accepted value (inclusive by default). At least one bound must be provided. max_valueNo* noneMaximum accepted value (inclusive by default). At least one bound must be provided. inclusiveNo trueWhether the bounds are inclusive. context_columnsNo noneList of additional columns to return with failing rows. Omit to return all columns.
* At least one of min_value or max_value must be provided.
With context columns
Min bound only
models :
- name : orders
columns :
- name : amount
data_tests :
- elementary.accepted_range_with_context :
min_value : 0
max_value : 10000
context_columns : [ order_id , customer_id , order_date ]
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
Parameter Required Default Description column_nameYes — The column to test for null values. row_conditionNo noneOptional SQL filter applied before testing (e.g. "status = 'active'"). context_columnsNo noneList of additional columns to return with failing rows. Omit to return all columns.
With row condition and context columns
models :
- name : subscriptions
columns :
- name : end_date
data_tests :
- elementary.expect_column_values_to_not_be_null_with_context :
row_condition : "status = 'active'"
context_columns : [ subscription_id , customer_id , start_date ]
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.
Parameters
Parameter Required Default Description column_nameYes — The column to test for uniqueness. row_conditionNo noneOptional SQL filter applied before testing. context_columnsNo noneList of additional columns to return with failing rows. Omit to return all columns.
models :
- name : customers
columns :
- name : email
data_tests :
- elementary.expect_column_values_to_be_unique_with_context :
context_columns : [ customer_id , created_at , name ]
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.
Requires dbt_expectations to be installed in your project.
Parameters
Parameter Required Default Description column_nameYes — The column to test. regexYes — The regular expression pattern to match. row_conditionNo noneOptional SQL filter applied before testing. is_rawNo falseWhether the regex is a raw string. flagsNo ""Optional regex flags (adapter-dependent). context_columnsNo noneList of additional columns to return with failing rows. Omit to return all columns.
Email format validation with context
models :
- name : customers
columns :
- name : email
data_tests :
- elementary.expect_column_values_to_match_regex_with_context :
regex : "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+ \\ .[a-zA-Z]{2,}$"
context_columns : [ customer_id , name , created_at ]
relationships_with_context
elementary.relationships_with_context
Validates referential integrity between a child and parent table. Extends dbt’s built-in relationships test.
Parameters
Parameter Required Default Description column_nameYes — The foreign key column in the child model. toYes — The parent model (use ref() or source()). fieldYes — The column in the parent model to join to. context_columnsNo noneList of additional columns from the child model to return with failing rows. Omit to return all columns.
With context columns
Return all columns
models :
- name : orders
columns :
- name : customer_id
data_tests :
- elementary.relationships_with_context :
to : ref('customers')
field : id
context_columns : [ order_id , order_date , amount ]