Jinja Templates
Jinja templates let you build dynamic inputs inside blocks. Anywhere a block field accepts text, you can use Jinja expressions to pull in workflow state, block outputs, environment variables or computed values.
Core Syntax
{{ ... }}for expressions{% ... %}for control flow
{{ inputs.user_message }}
{{ summarize_block.output }}
{% if inputs.priority == "high" %}urgent{% else %}normal{% endif %}Variable References
Scout makes three namespaces available in every template:
inputs.field_name: fields from the Input block ({{ inputs.user_name }})block_id.output: output from a prior block ({{ classify.output }})_env.VAR_NAME: environment variables for secrets and config ({{ _env.API_KEY }})
Chain dot notation to reach nested fields: {{ fetch_user.output.email }}.
Common Use Cases
Build a prompt with workflow state
Pull user input and a prior block’s output into an LLM prompt:
You are a helpful assistant. The user asked: {{ inputs.question }}
Relevant context from the knowledge base:
{{ retrieval_block.output }}
Answer based only on the context above.Build an API payload dynamically
Construct a JSON body for an HTTP block:
{
"user_id": "{{ inputs.user_id }}",
"action": "{{ inputs.action }}",
"timestamp": "{{ datetime.now(timezone.utc).isoformat() }}"
}Conditional messaging
Branch output based on workflow state:
{% if inputs.priority == "high" %}
Urgent: {{ inputs.message }}
{% else %}
FYI: {{ inputs.message }}
{% endif %}Date and Time
Use __exp_global for simple date strings. Use datetime directly when you need custom formatting:
{# Simple date strings #}
{{ __exp_global.current_date }}
{{ __exp_global.current_datetime }}
{{ __exp_global.current_time_utc }}
{# Custom formatting #}
{{ datetime.now(timezone.utc).isoformat() }}
{{ datetime.now(ZoneInfo("America/Los_Angeles")).strftime('%Y-%m-%d %I:%M %p') }}Available objects: datetime, timezone, ZoneInfo.
Safe Templating Rules
- Reference specific fields, not whole objects.
{{ block.output.name }}is safer than{{ block.output }}because it fails loudly if the field is missing. - Keep logic out of templates. If a conditional grows beyond one line, move it into a Conditional block instead.
- Test in Console before deploying. Console shows rendered template output so you catch bad references before they hit production.
- Use
_envfor secrets. Never hardcode credentials or tokens in a template.
Next Steps
- Logic and State: Understand variable flow and references
- Console: Validate rendered template output
- Creating Workflows: Build cleaner workflow architectures
Built with ❤️ by Scout OS
Last updated on