<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kam Haripara</title>
    <description>The latest articles on DEV Community by Kam Haripara (@kharipara).</description>
    <link>https://dev.to/kharipara</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4239931%2F19fdbc9f-6fd3-4bce-9ae9-5e1b15b967c8.jpg</url>
      <title>DEV Community: Kam Haripara</title>
      <link>https://dev.to/kharipara</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kharipara"/>
    <language>en</language>
    <item>
      <title>dbt source freshness: the check you configured but never run</title>
      <dc:creator>Kam Haripara</dc:creator>
      <pubDate>Mon, 23 Nov 2026 23:45:25 +0000</pubDate>
      <link>https://dev.to/kharipara/dbt-source-freshness-the-check-you-configured-but-never-run-580n</link>
      <guid>https://dev.to/kharipara/dbt-source-freshness-the-check-you-configured-but-never-run-580n</guid>
      <description>&lt;p&gt;It's easy to add a &lt;code&gt;freshness:&lt;/code&gt; 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. &lt;code&gt;not_null&lt;/code&gt;, &lt;code&gt;unique&lt;/code&gt; and &lt;code&gt;accepted_values&lt;/code&gt; 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.&lt;/p&gt;

&lt;p&gt;Everything below is from the dbt docs (&lt;a href="https://docs.getdbt.com/reference/resource-properties/freshness" rel="noopener noreferrer"&gt;freshness config&lt;/a&gt;, &lt;a href="https://docs.getdbt.com/reference/commands/source" rel="noopener noreferrer"&gt;dbt source command&lt;/a&gt;, &lt;a href="https://docs.getdbt.com/reference/commands/build" rel="noopener noreferrer"&gt;dbt build&lt;/a&gt;). Check the page for your dbt version, because some of it has moved recently.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. &lt;code&gt;dbt build&lt;/code&gt; does not run freshness
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;dbt build&lt;/code&gt; 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.&lt;/p&gt;

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

&lt;p&gt;Freshness has its own command:&lt;/p&gt;

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

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. A minimal config that actually checks something
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;sources&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;shop&lt;/span&gt;
    &lt;span class="na"&gt;database&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;raw&lt;/span&gt;
    &lt;span class="na"&gt;config&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;freshness&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;warn_after&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;count:&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;period:&lt;/span&gt; &lt;span class="s"&gt;hour&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;error_after&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;count:&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;period:&lt;/span&gt; &lt;span class="s"&gt;hour&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;loaded_at_field&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;_etl_loaded_at&lt;/span&gt;
    &lt;span class="na"&gt;tables&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;orders&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;customers&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;country_codes&lt;/span&gt;
        &lt;span class="na"&gt;config&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;freshness&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;   &lt;span class="c1"&gt;# reference data, rarely changes
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rules worth knowing:&lt;/p&gt;

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

&lt;p&gt;For the &lt;code&gt;orders&lt;/code&gt; table above, dbt runs roughly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt;
  &lt;span class="nb"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_etl_loaded_at&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;max_loaded_at&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="kc"&gt;current_timestamp&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;snapshotted_at&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shop&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;orders&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and compares the gap with your thresholds.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Pick the right timestamp
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;loaded_at_field&lt;/code&gt; should answer "when did this row land in the warehouse?", not "when did the business event happen?".&lt;/p&gt;

&lt;p&gt;If you point it at an event timestamp such as &lt;code&gt;order_date&lt;/code&gt;, 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 &lt;code&gt;_etl_loaded_at&lt;/code&gt;) tracks the thing you actually care about.&lt;/p&gt;

&lt;p&gt;Two adjustments, adapted from the docs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# a date column, cast so the comparison works
&lt;/span&gt;&lt;span class="na"&gt;loaded_at_field&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"completed_date::timestamp"&lt;/span&gt;

&lt;span class="c1"&gt;# a non-UTC timestamp, converted to UTC (Snowflake syntax)
&lt;/span&gt;&lt;span class="na"&gt;loaded_at_field&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"convert_timezone('Australia/Sydney', 'UTC', created_at_local)"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. No load timestamp? You have options
&lt;/h2&gt;

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

&lt;h2&gt;
  
  
  5. Keep the query cheap on big tables
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;max(loaded_at)&lt;/code&gt; over a large table can scan a lot. The &lt;code&gt;filter&lt;/code&gt; option adds a &lt;code&gt;WHERE&lt;/code&gt; clause to the freshness query only:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;tables&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;events&lt;/span&gt;
    &lt;span class="na"&gt;config&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;loaded_at_field&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;_etl_loaded_at&lt;/span&gt;
      &lt;span class="na"&gt;freshness&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;error_after&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;count:&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;period:&lt;/span&gt; &lt;span class="s"&gt;hour&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"_etl_loaded_at &amp;gt;= dateadd(day, -2, current_date)"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It doesn't affect other uses of the source, and it doesn't apply to &lt;code&gt;loaded_at_query&lt;/code&gt; (put the filter inside that query instead).&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Run it before the build
&lt;/h2&gt;

&lt;p&gt;The ordering that makes sense for most teams: check sources first, and only build when they are fresh enough.&lt;/p&gt;

&lt;p&gt;In Airflow, two tasks are enough:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;airflow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;standard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;operators&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bash&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;BashOperator&lt;/span&gt;

&lt;span class="n"&gt;freshness&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BashOperator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;task_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"dbt_source_freshness"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;bash_command&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"cd /opt/dbt &amp;amp;&amp;amp; dbt source freshness"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;build&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BashOperator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;task_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"dbt_build"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;bash_command&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"cd /opt/dbt &amp;amp;&amp;amp; dbt build"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;freshness&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;build&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(On Airflow 2, import &lt;code&gt;BashOperator&lt;/code&gt; from &lt;code&gt;airflow.operators.bash&lt;/code&gt;.)&lt;/p&gt;

&lt;p&gt;An error-level stale source makes the command exit non-zero, the task fails, and &lt;code&gt;dbt_build&lt;/code&gt; 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 &lt;code&gt;trigger_rule="all_done"&lt;/code&gt; on the build task and alert on the freshness task's failure.&lt;/p&gt;

&lt;p&gt;On the dbt platform, the job settings have a source freshness option under execution settings, so you don't need a separate step.&lt;/p&gt;

&lt;p&gt;The dbt docs also suggest running freshness on its own schedule and keeping the results. &lt;code&gt;sources.json&lt;/code&gt; / &lt;code&gt;freshness.json&lt;/code&gt; 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. What freshness won't tell you
&lt;/h2&gt;

&lt;p&gt;Freshness answers one question: is the newest row recent enough? It's a good question, but it has edges:&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Checklist
&lt;/h2&gt;

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




&lt;p&gt;&lt;em&gt;I'm building &lt;a href="https://rowmonitor.com" rel="noopener noreferrer"&gt;Row Monitor&lt;/a&gt;, which checks freshness, row counts and schema from outside the pipeline, for the "nothing ran at all" case. The checklist above works without it.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>dbt</category>
      <category>dataengineering</category>
      <category>airflow</category>
      <category>dataquality</category>
    </item>
  </channel>
</rss>
