Jinja and template variables
abt uses Jinja2 in several places. Which callables exist depends on the file type (similar to dbt: SQL models get ref(), YAML properties get a smaller context).
Quick reference
| Location | var() |
env_var() |
context.* |
source() |
|---|---|---|---|---|
Agent body (markdown after ---) |
Yes | No | Yes | No |
| Agent frontmatter (selected keys) | Yes | Yes | No | No |
| Agent prompts (compiled text) | Yes | No | Yes | Yes — compile records source() refs; runtime composes payloads into the user message |
sources/ / exposures/ config: (catalog) |
Yes | Yes | No | No |
Inline ref-site binding (retrievers:/transformers: single-key map in agent frontmatter; source/exposure nodes and trigger: bind vars: in workflows/*.yaml) |
Yes | Yes | No | No |
Transformer config: (in transformers/*.yaml) |
Yes | Yes | No | No |
| context/*.md | Yes | No | Yes | No |
abt compilerenders{{ var() }}in the rows above with strict resolution: missing required vars fail the compile.- Config templates (compile and run time) render in a Jinja sandbox: filters,
{% if %}/{% for %}, string methods, building a local list or dict ({% set _ = items.append(x) %}) andenv_var()work; attribute access to Python internals (__class__,__globals__) raisesSecurityError. - Runtime renders
config:strings with the realenv_var():sources/andexposures/: compile rendersvar()in each top-level value and keeps the ones that useenv_var(), with theirvar()calls filled in. Only those strings, and the strings inside a nested map or list (wherevar()still resolves at run time), render when the source fetches or the exposure fires. Any other string is final text: avar()value containing{{ ... }}reaches the provider as that literal text. An ad-hoc--exposevalue follows the same rule:var()renders when the exposure is built and only itsenv_var()calls render at run time.middleware:: the stacks ofabt.yaml, the agent and the framework merge first, and the build then renders every template-looking string of the merged result. Avar()value that contains{is written as a Jinja string expression, so that render gives back the value itself and never evaluates it; this includes two values that only form{{once joined. Inside such a template a value containing braces is that expression, so a comparison or filter on it sees the wrapped form, not the bare text.
- Agent-to-agent delegation is not a Jinja callable. It is declared with a
subagents:list in the calling agent's YAML frontmatter — see Subagents.
Full Jinja2, not a restricted subset
Agent bodies and prompts render through a real jinja2.Environment — every Jinja construct works, not just the callables above:
{% for topic in ["billing", "shipping"] %}
- {{ topic | capitalize }}
{% endfor %}
{% if var('tier', 'free') == 'enterprise' %}
Escalate to the senior queue.
{% endif %}
Undefined names raise (StrictUndefined) — a typo or a leftover unsupported call fails the compile instead of rendering blank.
Text you pass at run time (abt run -p, abt dispatch -p, abt chat lines, and the SDK's prompt/prompt_override) still renders {{ var() }} and control flow, but in a Jinja sandbox with env_var() disabled: attribute access to Python internals (__class__, __globals__) raises SecurityError, and var() is a lookup only. The sandbox does not bound CPU or memory, so an app that passes user text as a prompt should limit its length. {% import %} of your macro directories keeps working. Variables are not secrets: read a secret with env_var() in a config, not with var().
Macros work like dbt: define them in macros/*.md, import by filename.
{# macros/greetings.md #}
{% macro greet(name) %}Hello, {{ name }}!{% endmacro %}
{% import 'greetings.md' as g %}
{{ g.greet('Ada') }}
Want to show Jinja syntax without it rendering? Put it in a code span or fence — those are masked before parsing.
Agent frontmatter
Use a quoted YAML string so {{ parses as text:
---
description: My agent
model_id: "{{ var('model_default') }}"
temperature: "{{ var('agent_temp') }}"
---
Define values in vars.yaml (project root), under vars: in abt.yaml, or pass --vars.
Precedence (lowest → highest):
vars.yaml— project-level defaults (dbt 1.12 style)abt.yamlvars:— inline overrides- CLI
--vars— runtime overrides (the agent invoke API'svarsfield is the same layer, limited to variables the agent's body references)
# vars.yaml (project root, sibling to abt.yaml)
model_name: gpt-4o
environment: production
max_retries: 3
env_var() — reading process environment variables
{{ env_var('NAME') }} reads directly from the process environment (not vars.yaml/abt.yaml), dbt-style, in the places the table above marks Yes (not in prompt text, see below):
{{ env_var('FEATURE_FLAG_X', 'false') }}
Missing + no default fails the compile, same as var(). Because environment variables are
always strings, an optional type= kwarg coerces the value — pass "bool", "int", or
"float" (default "str", unchanged):
{{ env_var('MAX_RETRIES', '3', type='int') }}
{{ env_var('DEBUG_MODE', 'false', type='bool') }}
A value that doesn't parse as the declared type (e.g. MAX_RETRIES=nope with type='int')
fails the compile with a clear error rather than silently falling back to a string. A string
default is coerced the same way, so the return type doesn't depend on whether the value came
from the environment or the default.
env_var() is not allowed in an agent body, prompts/*.md or context/*.md. A rendered body is
copied into target/manifest.json, target/compiled/, the partial-parse cache and the docs site, which
are meant to be shared, so an environment value would leak into them. Compile fails with an error that
names the call. Use {{ var('NAME') }} with vars: (vars.yaml, abt.yaml or --vars) for non-secret
settings, and keep credentials in profiles.yaml credentials:. Where a value is needed at run time,
read it from a tool, source or context provider. In frontmatter, env_var() is rendered at compile for
scalar settings such as temperature, so never put a secret there. In the config: of sources, exposures
and middleware, and in on_success/on_failure handler kwargs, a value that calls env_var() is kept
unrendered in the manifest and rendered whole at run time, so it is the right place for tokens. An unset
variable with no default fails there at run time, not at compile; for a handler it is logged as an error naming the
variable and recorded as a failed handler, which --fail-on-handler-error and config.handlers.fail_fast escalate.
Filters, or defaults and {% if %} see the real value
("{{ env_var('REGION') | lower }}" works). var() calls in such a value are compile-time:
their value is frozen into the kept expression, so their arguments must be literals.
Every env_var() a compile resolves is recorded (name only) in metadata.env_vars; changing
one of those variables invalidates the partial-parse cache.
Agent prompts, source(), and upstream()
A source is a workflow node, not agent frontmatter. Agent bodies can't call upstream();
compile rejects it. To pass a predecessor's output into an agent, put a prompts/*.md node
between them and read the output there with {{ upstream('node_name') }}. At dispatch time
the call is replaced with that node's output text. A name that isn't an actual predecessor is
left as literal text. Only references you wrote in the prompt are replaced: in a rendered prompt a var() value gets an invisible zero-width space between any two {, so a variable holding {{ upstream('x') }} stays text. See Sources and Workflows.
Not templated
- Retriever
query:(inretrievers/*.yaml) — supports{{ task() }}, exact-match{{ var('key') }},{{ source('name') }}, and{{ upstream('name') }}, but these are expanded by simple string replacement, not a Jinja render pass. Any other Jinja syntax is left as literal text. - Skills and few-shots file bodies — plain text.