Loading...
Loading...
Adds schema tests and data quality validation to dbt models. Use when working with dbt tests for: (1) Adding or modifying tests in schema.yml files (2) Task mentions "test", "validate", "data quality", "unique", "not_null", or "accepted_values" (3) Ensuring data integrity - primary keys, foreign keys, relationships (4) Debugging test failures or understanding why dbt test failed Matches existing project test patterns and YAML style before adding new tests.
npx skill4agent add altimateai/data-engineering-skills testing-dbt-models# Find all schema.yml files with tests
find . -name "schema.yml" -exec grep -l "tests:" {} \;
# Read existing tests to learn patterns
cat models/staging/schema.yml | head -100
cat models/marts/schema.yml | head -100
# Check for custom tests or dbt packages
ls tests/
cat packages.yml 2>/dev/nullcat models/<path>/<model_name>.sqlcat models/<path>/schema.yml | grep -A 50 "<model_name>"
# or
find . -name "schema.yml" -exec grep -l "<model_name>" {} \;| Column Type | Recommended Tests |
|---|---|
| Primary key | |
| Foreign key | |
| Categorical | |
| Required field | |
| Date/timestamp | |
| Boolean | |
version: 2
models:
- name: model_name
description: "Brief description of what this model contains"
columns:
- name: primary_key_column
description: "Unique identifier for this record"
tests:
- unique
- not_null
- name: foreign_key_column
description: "Reference to related_model"
tests:
- not_null
- relationships:
to: ref('related_model')
field: related_key_column
- name: status
description: "Current status of the record"
tests:
- not_null
- accepted_values:
values: ['pending', 'active', 'completed', 'cancelled']
- name: created_at
description: "Timestamp when record was created"
tests:
- not_null# Test specific model
dbt test --select <model_name>
# Test with upstream
dbt test --select +<model_name>| Failure | Likely Cause | Fix |
|---|---|---|
| Duplicate records | Add deduplication in model |
| NULL values in source | Add COALESCE or filter |
| Orphan records | Add WHERE clause or fix upstream |
| New/unexpected values | Update accepted values list |
tests:
- unique
- not_null
- accepted_values:
values: ['a', 'b', 'c']
- relationships:
to: ref('other_model')
field: idtests:
- dbt_utils.expression_is_true:
expression: "amount >= 0"
- dbt_utils.recency:
datepart: day
field: created_at
interval: 1tests/<test_name>.sql-- tests/assert_positive_revenue.sql
select *
from {{ ref('orders') }}
where revenue < 0