Built-in Jinja context variables help you access useful information automatically inside your dbt models and macros. They make your code smarter and easier to write.
0
0
Built-in Jinja context variables in dbt
Introduction
When you want to know the current model's name or path inside a dbt model.
When you need to get the current execution environment or target database.
When you want to access the current project or profile details in your dbt code.
When you want to write macros that behave differently based on the current context.
When you want to debug or log information about the current dbt run.
Syntax
dbt
{{ context_variable_name }}You use double curly braces {{ }} to access context variables in Jinja.
Context variables are automatically available; you don't need to define them.
Examples
Returns the current model's identifier (database.schema.table).
dbt
{{ this }}Gives the name of the current target environment (like 'dev' or 'prod').
dbt
{{ target.name }}Returns the name of your current dbt project.
dbt
{{ project_name }}Shows the timestamp when the current dbt run started.
dbt
{{ run_started_at }}Sample Program
This dbt model selects some built-in context variables and shows them as columns. It helps you see what values these variables hold during a run.
dbt
select '{{ this }}' as model_name, '{{ target.name }}' as target_env, '{{ project_name }}' as project, '{{ run_started_at }}' as run_time from {{ this }} limit 1
OutputSuccess
Important Notes
Context variables depend on where you use them (model, macro, test).
Some variables like this give you the current model info automatically.
Use these variables to make your dbt code dynamic and environment-aware.
Summary
Built-in Jinja context variables provide automatic info about your dbt run and environment.
They help you write flexible and reusable dbt models and macros.
Use double curly braces {{ }} to access these variables inside your dbt code.