dbt "Compilation Error: X is undefined" Jinja var in CI
dbt rendered a model template and hit a Jinja name it does not know: a var() with no default and no definition, or a variable that was never set. Rendering stops because the value is undefined.
What this error means
dbt compile or run fails with "Compilation Error in model X ... 'my_var' is undefined" pointing at the template that used the variable.
dbt
Compilation Error in model daily_revenue (models/marts/daily_revenue.sql)
'start_date' is undefinedCommon causes
A var() has no default and was not passed
The model calls var('start_date') but the run did not supply it via --vars or dbt_project.yml, so it is undefined.
A variable is expected from the CI invocation
A run-scoped variable the model relies on was omitted from the dbt command in CI.
How to fix it
Supply the variable or a default
- Pass the value with
--varsin the CI command, or - Give
var()a default so it renders without an explicit value. - Re-run
dbt compileto confirm it renders.
Terminal
dbt run --vars '{"start_date": "2024-01-01"}'Define a project-level default
Declare the variable in dbt_project.yml or use a default in the call so CI never depends on ad hoc flags.
models/marts/daily_revenue.sql
-- in the model
where created_at >= '{{ var("start_date", "2024-01-01") }}'How to prevent it
- Give var() a sensible default, or pass it explicitly in CI.
- Declare shared vars in dbt_project.yml so runs are reproducible.
- Run
dbt compilein CI to catch undefined variables before build.
Related guides
dbt "Compilation Error: macro not found" in CIFix dbt "Compilation Error: macro X not found" in CI - a model or config calls a macro that is not defined in…
dbt Compilation Error: model depends on a node not found (ref) in CIFix dbt "Compilation Error: Model X depends on a node named Y which was not found" in CI - a ref() points at…
dbt "Database Error in model" SQL error in CIFix dbt "Database Error in model X" in CI - the compiled SQL ran against the warehouse and the database rejec…