It's easy to add a freshness: block to a dbt source and assume you're covered. Whether anything actually runs it is a separate question, and it matters, because freshness is the one dbt check that catches a source that simply stopped arriving. not_null, unique and accepted_values all pass happily on yesterday's data. This post covers how dbt freshness works, the parts of the config that trip people up, and how to wire it into a schedule so it fails loudly.

Everything below is from the dbt docs (freshness config, dbt source command, dbt build). Check the page for your dbt version, because some of it has moved recently.

1. dbt build does not run freshness

The dbt build docs list what it does: run models, test tests, snapshot snapshots, seed seeds (and build user-defined functions from v1.11). Freshness is not on the list.

So a project whose only scheduled command is dbt build has freshness thresholds that are never evaluated. The YAML parses, the docs site shows the thresholds, and nothing ever checks them.

Freshness has its own command:

  • dbt source freshness: the long-standing command. It checks sources only and writes target/sources.json. The current docs call it legacy but still supported.
  • dbt freshness: the newer top-level command. It checks every source and model that has a freshness config and writes target/freshness.json (plus sources.json for backward compatibility when sources are included).

Use whichever your version supports. When a table is stale, dbt reports a warning or an error and exits with a non-zero exit code, which is exactly what you want a scheduler to see.

2. A minimal config that actually checks something

sources: - name: shop database: raw config: freshness: warn_after: {count: 12, period: hour} error_after: {count: 24, period: hour} loaded_at_field: _etl_loaded_at tables: - name: orders - name: customers - name: country_codes config: freshness: null # reference data, rarely changes 

Rules worth knowing:

  • You need warn_after or error_after. If neither is set, dbt does not check freshness for that resource. Each needs both count and period (minute, hour or day). Setting only one of the two parses with a warning but errors when freshness runs.
  • Config is hierarchical. Freshness and loaded_at_field on the source apply to every table; a table-level value overrides it. Use freshness: null to opt a table out.
  • The config location moved. freshness moved under config: in v1.9 and loaded_at_field in v1.10. Older top-level placements may still appear in examples online.

For the orders table above, dbt runs roughly:

select max(_etl_loaded_at) as max_loaded_at, current_timestamp as snapshotted_at from raw.shop.orders 

and compares the gap with your thresholds.

3. Pick the right timestamp

loaded_at_field should answer "when did this row land in the warehouse?", not "when did the business event happen?".

If you point it at an event timestamp such as order_date, a source that sends late-arriving events will look stale when the load is healthy, and a quiet weekend will look like a broken pipeline. A load timestamp written by your ingestion tool (many tools add one; the dbt docs example uses _etl_loaded_at) tracks the thing you actually care about.

Two adjustments, adapted from the docs:

# a date column, cast so the comparison works loaded_at_field: "completed_date::timestamp" # a non-UTC timestamp, converted to UTC (Snowflake syntax) loaded_at_field: "convert_timezone('Australia/Sydney', 'UTC', created_at_local)" 

The timezone one is easy to miss. If the column is local time and the comparison is UTC, every table is off by your UTC offset, and your thresholds quietly become wrong by that amount.

4. No load timestamp? You have options

  • Leave out loaded_at_field. dbt then uses warehouse metadata where the adapter supports it. The docs warn this isn't reliable on BigQuery for wildcard tables like events_*, and there is a flag (bigquery_reject_wildcard_metadata_source_freshness) that turns that case into an error instead of a wrong answer.
  • Use loaded_at_query (v1.10+): any SQL that returns the latest load timestamp. You can't set it together with loaded_at_field; that's a parse error.

5. Keep the query cheap on big tables

max(loaded_at) over a large table can scan a lot. The filter option adds a WHERE clause to the freshness query only:

tables: - name: events config: loaded_at_field: _etl_loaded_at freshness: error_after: {count: 6, period: hour} filter: "_etl_loaded_at >= dateadd(day, -2, current_date)" 

It doesn't affect other uses of the source, and it doesn't apply to loaded_at_query (put the filter inside that query instead).

6. Run it before the build

The ordering that makes sense for most teams: check sources first, and only build when they are fresh enough.

In Airflow, two tasks are enough:

from airflow.providers.standard.operators.bash import BashOperator freshness = BashOperator( task_id="dbt_source_freshness", bash_command="cd /opt/dbt && dbt source freshness", ) build = BashOperator( task_id="dbt_build", bash_command="cd /opt/dbt && dbt build", ) freshness >> build 

(On Airflow 2, import BashOperator from airflow.operators.bash.)

An error-level stale source makes the command exit non-zero, the task fails, and dbt_build doesn't run on stale data. Whether you want that is a team decision: some teams prefer to build anyway and alert. If so, set trigger_rule="all_done" on the build task and alert on the freshness task's failure.

On the dbt platform, the job settings have a source freshness option under execution settings, so you don't need a separate step.

The dbt docs also suggest running freshness on its own schedule and keeping the results. sources.json / freshness.json are plain JSON, so storing them per run gives you a history of how late each source usually is, which is how you choose thresholds that aren't guesses.

7. What freshness won't tell you

Freshness answers one question: is the newest row recent enough? It's a good question, but it has edges:

  • A short load looks fresh. If today's load wrote 40 rows instead of 40,000, max(_etl_loaded_at) is still recent. Pair freshness with a row-count or volume test on the tables that matter.
  • It only runs when something runs it. If the scheduler is down, or the DAG that runs dbt source freshness never starts, nothing evaluates the threshold and nothing alerts. A check from outside the pipeline covers that case.
  • Models are separate. dbt source freshness checks sources only. If you need freshness on models, that's the newer dbt freshness command with a freshness config on the model.

Checklist

  1. Every source you depend on has warn_after and/or error_after, or an explicit freshness: null.
  2. loaded_at_field is a load timestamp, in UTC (or converted).
  3. Large tables use filter.
  4. dbt source freshness (or dbt freshness) is a scheduled step before dbt build, not just YAML.
  5. Volume checks sit alongside freshness for the tables people make decisions from.

I'm building Row Monitor, which checks freshness, row counts and schema from outside the pipeline, for the "nothing ran at all" case. The checklist above works without it.