Built-in & Custom Data Tests, Sources & Freshness Checks
Declare source freshness and generic/custom tests so bad data fails the build loudly.
In plain words
Database/schema/table and owner. Next, stable loaded_at field and thresholds. Finally, severity, stored failures, and owner route.
Think of it like…
Source freshness is the receiving dock's clock, tests are inspection gauges, and severity is the difference between quarantine at the gate and a note left for tomorrow.
Where you’ve seen it
sources.yml sets freshness: {warn_after: {count: 30, unit: minute}, error_after: {count: 2, unit: hour}} and tests: [unique, not_null, relationships]; dbt source freshness exits on the SLO breach.
Words you’ll hear
- Tests
- Parameterized assertions such as unique/not_null/relationships packaged in dbt YAML and compiled as model queries.
- Sources
- First-class raw table nodes with descriptions, lineage, owners, and optional freshness metadata.
- Freshness
- A source timestamp compared with current time under warning/error intervals to detect missing producer loads.
- Operational boundary
- A freshness threshold on a source field that updates on every warehouse read is meaningless, expensive full-table tests can gate every tiny model, and warning-only failures can allow a known broken KPI to publish. Set
loaded_at_fieldto the true producer/ingest timestamp, classify tests as blocking or warn by contract, store failures for diagnosis, and select critical tests in production while preserving broader CI coverage.
Visual diagram
Theory & deep dive
Tests: the working mechanism
dbt source declarations document raw nodes and freshness queries, generic tests assert constraints such as not null/unique/relationships, and singular/custom SQL tests encode domain rules.
Database/schema/table and owner. Stable loaded_at field and thresholds, then standard and domain-specific tests; this exposes the state governed by Freshness.
sources.yml sets freshness: {warn_after: {count: 30, unit: minute}, error_after: {count: 2, unit: hour}} and tests: [unique, not_null, relationships]; dbt source freshness exits on the SLO breach.
Built-in & Custom Data Tests, Sources & Freshness Checks: failure mode and production response
A freshness threshold on a source field that updates on every warehouse read is meaningless, expensive full-table tests can gate every tiny model, and warning-only failures can allow a known broken KPI to publish.
Set loaded_at_field to the true producer/ingest timestamp, classify tests as blocking or warn by contract, store failures for diagnosis, and select critical tests in production while preserving broader CI coverage. Track Warn/error delay as "freshness thresholds relative to consumer SLO", and make Test selectivity visible to the dataset owner.
loaded_at_field to the true producer/ingest timestamp, classify tests as blocking or warn by contract, store failures for diagnosis, and select critical tests in production while preserving broader CI coverage.How it works, step by step
Step 1 of 41. Declare source
Database/schema/table and owner. dbt source declarations document raw nodes and freshness queries, generic tests assert constraints such as not null/unique/relationships, and singular/custom SQL tests encode domain rules.
- Warn/error delay
- freshness thresholds relative to consumer SLO
- Sources
- First-class raw table nodes with descriptions, lineage, owners, and optional freshness metadata.
When to use it & trade-offs
What it is
dbt source declarations document raw nodes and freshness queries, generic tests assert constraints such as not null/unique/relationships, and singular/custom SQL tests encode domain rules. sources.yml sets freshness: {warn_after: {count: 30, unit: minute}, error_after: {count: 2, unit: hour}} and tests: [unique, not_null, relationships]; dbt source freshness exits on the SLO breach.
Why it matters: A freshness threshold on a source field that updates on every warehouse read is meaningless, expensive full-table tests can gate every tiny model, and warning-only failures can allow a known broken KPI to publish. Set loaded_at_field to the true producer/ingest timestamp, classify tests as blocking or warn by contract, store failures for diagnosis, and select critical tests in production while preserving broader CI coverage.
When to reach for it
- Declare source freshness and generic/custom tests so bad data fails the build loudly.
- Choose Tests because it provides this capability: Parameterized assertions such as unique/not_null/relationships packaged in dbt YAML and compiled as model queries.
- Keep evidence for Warn/error delay at "freshness thresholds relative to consumer SLO" so the last production stage-Gate and diagnose - severity, stored failures, and owner route-remains testable.
When to avoid or be careful
- A freshness threshold on a source field that updates on every warehouse read is meaningless, expensive full-table tests can gate every tiny model, and warning-only failures can allow a known broken KPI to publish.
- Do not conflate Sources with Tests. The second concept contributes different behavior: First-class raw table nodes with descriptions, lineage, owners, and optional freshness metadata.
- Release only after this guardrail is in place: Set
loaded_at_fieldto the true producer/ingest timestamp, classify tests as blocking or warn by contract, store failures for diagnosis, and select critical tests in production while preserving broader CI coverage.
Tests / Sources / Freshness - roles, limits, and operating cost
Strengths: Parameterized assertions such as unique/not_null/relationships packaged in dbt YAML and compiled as model queries. dbt source declarations document raw nodes and freshness queries, generic tests assert constraints such as not null/unique/relationships, and singular/custom SQL tests encode domain rules.
Watch out: A freshness threshold on a source field that updates on every warehouse read is meaningless, expensive full-table tests can gate every tiny model, and warning-only failures can allow a known broken KPI to publish.
Strengths: First-class raw table nodes with descriptions, lineage, owners, and optional freshness metadata. In this workflow it supports: Assert contract - standard and domain-specific tests.
Watch out: The operating cost is real: failing rows bounded and explainable.
Strengths: A source timestamp compared with current time under warning/error intervals to detect missing producer loads. Its output can be checked with Failure retention.
Watch out: Operating guardrail: Set loaded_at_field to the true producer/ingest timestamp, classify tests as blocking or warn by contract, store failures for diagnosis, and select critical tests in production while preserving broader CI coverage.
Interview signals & numbers to know
When this topic comes up
- “Where is the failure boundary for Tests, and how would Warn/error delay reveal it?”
- “Why is Sources distinct from this behavior: a source timestamp compared with current time under warning/error intervals to detect missing producer loads?”
- Production clue: A freshness threshold on a source field that updates on every warehouse read is meaningless, expensive full-table tests can gate every tiny model, and warning-only failures can allow a known broken KPI to publish.
- Design probe: Set loaded_at_field to the true producer/ingest timestamp, classify tests as blocking or warn by contract, store failures for diagnosis, and select critical tests in production while preserving broader CI coverage.
Benchmarks & rules of thumb
- Warn/error delay
- freshness thresholds relative to consumer SLO
- Test selectivity
- failing rows bounded and explainable
- Failure retention
- store or expose results for owner debugging
Common mistakes & follow-ups
Common interview mistakes
- A freshness threshold on a source field that updates on every warehouse read is meaningless, expensive full-table tests can gate every tiny model, and warning-only failures can allow a known broken KPI to publish.
- Reporting success from a job exit code without checking Warn/error delay and Test selectivity.
- Treating this example as complete without replay, rollback, or access boundaries:
sources.ymlsetsfreshness: {warn_after: {count: 30, unit: minute}, error_after: {count: 2, unit: hour}}andtests: [unique, not_null, relationships];dbt source freshnessexits on the SLO breach.
Likely interviewer follow-ups
- How would you prove this contract instead of only checking that the command ran: Parameterized assertions such as unique/not_null/relationships packaged in dbt YAML and compiled as model queries.
- What does the recovery plan do when this occurs? A freshness threshold on a source field that updates on every warehouse read is meaningless, expensive full-table tests can gate every tiny model, and warning-only failures can allow a known broken KPI to publish.
- When is Tests insufficient for Test selectivity, and what does adding Sources cost in Warn/error delay?
loaded_at_field to the true producer/ingest timestamp, classify tests as blocking or warn by contract, store failures for diagnosis, and select critical tests in production while preserving broader CI coverage.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Built-in & Custom Data Tests, Sources & Freshness Checks with data engineer interview Q&A and hands-on practice.