Overview
Compozy's YAML template engine enables dynamic configuration by combining standard YAML syntax with Go template expressions. This allows you to create flexible, reusable configurations that adapt to different contexts and data sources.
Core Capabilities
Dynamic Values
Resource References
Data Transformations
Conditional Logic
Template Expression Syntax
Template expressions use Go template syntax wrapped in double curly braces. Here are the essential patterns:
Basic Value Injection
Access data from your workflow context:
# Access workflow input
city: "{{ .workflow.input.city }}"
# Access environment variables
api_key: "{{ .env.OPENAI_API_KEY }}"
# Access task outputs
weather: "{{ .tasks.weather_check.output.temperature }}"
When to use: Direct access to known data sources without transformation.
Common Use Cases
Dynamic Task Configuration
Configure tasks based on runtime data:
- id: api_call
type: basic
$use: tool(local::tools.#(id=="http_request"))
with:
url: "{{ .env.API_BASE_URL }}/users/{{ .workflow.input.user_id }}"
method: "{{ .workflow.input.method | default 'GET' }}"
headers:
Authorization: "Bearer {{ .env.API_TOKEN }}"
Use case: When you need to configure tasks with different URLs, parameters, or settings based on input data.
Template Processing
The template engine processes your YAML configurations in 5 phases:
Parse Phase
The engine identifies template expressions marked with {{ }}
and prepares them for processing.
Context Resolution
Data from workflow input, task outputs, and environment variables is collected into a context map.
Template Rendering
Template expressions are evaluated using the Go template engine with Sprig functions.
Type Conversion
String results are converted to numbers, booleans, or objects as needed.
Reference Resolution
$ref
and $use
directives are resolved to actual schemas, tools, and agents.
Security Features
Available Security Functions
htmlEscape
htmlAttrEscape
jsEscape
Security Best Practice
# ❌ DANGEROUS: Direct user input
dangerous_output: "{{ .user_input }}"
# ✅ SAFE: Properly escaped user input
safe_output: "{{ .user_input | htmlEscape }}"
References
Build your template expertise progressively: