Variables let one model run for different values without changing its code: a date to reprocess, a
region, a flag. The model reads the value with var(), and the command line supplies it with --vars.
Copy and paste
Read the variable in a model, with a default:
-- models/marts/orders_daily.sql
select order_date, count(*) as orders, sum(amount) as revenue
from {{ ref('stg_orders') }}
where order_date = '{{ var("run_date", "2026-05-15") }}'
group by order_date
Pass a value:
dbt run -s orders_daily --vars '{run_date: "2026-05-14"}'
Several values, in YAML or JSON:
dbt run -s orders_daily --vars '{run_date: "2026-05-14", region: eu}'
dbt run -s orders_daily --vars '{"run_date": "2026-05-14", "region": "eu"}'
A project-wide default in dbt_project.yml:
vars:
run_date: "2026-05-15"
What the model receives
dbt compile shows the result:
| Command | Compiled filter |
|---|---|
dbt compile -s orders_daily |
where order_date = '2026-05-15' |
dbt compile -s orders_daily --vars '{run_date: "2026-05-14"}' |
where order_date = '2026-05-14' |
The order of precedence is: --vars on the command line, then vars: in dbt_project.yml, then the
default in var().
Quote dates
--vars is YAML, and YAML reads an unquoted 2026-05-14 as a date, not as text. In SQL it prints the
same, but string operations in Jinja fail. {{ var('run_date')[:7] }} stops with a compilation error
when the value is unquoted and returns 2026-05 when it is quoted. Write "2026-05-14".
A variable without a default
When a model uses var('region') without a default and nobody passes it, the run stops:
Compilation Error in model var_missing (models/marts/var_missing.sql)
Required var 'region' not found in config:
Vars supplied to var_missing = {}
Give every variable a default, in var() or in dbt_project.yml, unless the run really must not start
without it.
From Airflow
A scheduler passes the run date the same way:
dbt build --vars '{run_date: "{{ ds }}"}'
How to run dbt Core from Airflow with BashOperator shows the full task. For dates computed inside dbt itself, see how to get yesterday’s date in a dbt model.
Tested with dbt Core 1.12.