skills/dbt/testing-dbt-models/SKILL.md
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 skillsauth add altimateai/data-engineering-skills testing-dbt-modelsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Every model deserves at least one test. Primary keys need unique + not_null.
CRITICAL: Match the project's existing testing style before adding new tests.
# 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/null
Extract from existing tests:
cat models/<path>/<model_name>.sql
Identify: primary keys, foreign keys, categorical columns, date columns, business-critical fields.
cat 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 | unique, not_null |
| Foreign key | not_null, relationships |
| Categorical | accepted_values (ask user for valid values) |
| Required field | not_null |
| Date/timestamp | not_null |
| Boolean | accepted_values: [true, false] |
Match the existing style from step 1. Example format (adapt to project):
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>
Common failures and fixes:
| Failure | Likely Cause | Fix |
|---------|--------------|-----|
| unique fails | Duplicate records | Add deduplication in model |
| not_null fails | NULL values in source | Add COALESCE or filter |
| relationships fails | Orphan records | Add WHERE clause or fix upstream |
| accepted_values fails | New/unexpected values | Update accepted values list |
tests:
- unique
- not_null
- accepted_values:
values: ['a', 'b', 'c']
- relationships:
to: ref('other_model')
field: id
tests:
- dbt_utils.expression_is_true:
expression: "amount >= 0"
- dbt_utils.recency:
datepart: day
field: created_at
interval: 1
Create tests/<test_name>.sql:
-- tests/assert_positive_revenue.sql
select *
from {{ ref('orders') }}
where revenue < 0
tools
Delegates data engineering tasks to altimate-code, a specialized CLI agent with 100+ purpose-built data tools — SQL analysis, column-level lineage, dbt build/test/run, warehouse profiling, FinOps, and connectivity to Snowflake, BigQuery, Redshift, Databricks, Postgres, MySQL, DuckDB. Use this skill when the task needs live warehouse access, column lineage, multi-step data exploration, dbt builds against a real warehouse, or when the user explicitly invokes "altimate", "altimate-code", or "the data agent".
testing
Optimizes Snowflake SQL query performance from provided query text. Use when optimizing Snowflake SQL for: (1) User provides or pastes a SQL query and asks to optimize, tune, or improve it (2) Task mentions "slow query", "make faster", "improve performance", "optimize SQL", or "query tuning" (3) Reviewing SQL for performance anti-patterns (function on filter column, implicit joins, etc.) (4) User asks why a query is slow or how to speed it up
development
Optimizes Snowflake query performance using query ID from history. Use when optimizing Snowflake queries for: (1) User provides a Snowflake query_id (UUID format) to analyze or optimize (2) Task mentions "slow query", "optimize", "query history", or "query profile" with a query ID (3) Analyzing query performance metrics - bytes scanned, spillage, partition pruning (4) User references a previously run query that needs optimization Fetches query profile, identifies bottlenecks, returns optimized SQL with expected improvements.
data-ai
Finds and ranks expensive Snowflake queries by cost, time, or data scanned. Use when: (1) User asks to find slow, expensive, or problematic queries (2) Task mentions "query history", "top queries", "most expensive", or "slowest queries" (3) Analyzing warehouse costs or identifying optimization candidates (4) Finding queries that scan the most data or have the most spillage Returns ranked list of queries with metrics and optimization recommendations.