if: pattern to evaluate variables and route execution accordingly.
Steps inside this pattern inherit the same
max_retries, guardrails, and output_file policies as top-level steps. See Nested workflows → Retry, guardrails, and output_file.Quick Start
1
Python or YAML
Condition Syntax
Numeric Comparisons
>, <, >=, <=, ==, !=String Equality
==, != for exact matchesContains Check
in or contains keywordsBoolean Values
true, false for flagsNumeric Comparisons
Compare numbers using standard operators:String Equality
Match exact string values:Contains Check
Check if a string contains a substring:Nested Property Access
Access nested object properties:If Without Else
Theelse_steps parameter is optional. If omitted, nothing happens when the condition is false:
If Inside Loop
Combine conditional branching with loops for per-item decisions:- Python
- YAML
Nested Conditions
Create decision trees with nested if statements:How It Works
The user starts a flow with variables;if_ evaluates the condition and runs the matching branch.
API Reference
if_() Function
Condition expression with
{{variable}} placeholdersSteps to execute when condition is true
Steps to execute when condition is false (optional)
If Class
MAX_NESTING_DEPTH
Nested conditions count toward the maximum nesting depth of 5 levels.
Best Practices
Use Clear Condition Names
Use Clear Condition Names
Make conditions readable:
{{user.is_verified}} == true is clearer than {{v}} == 1Provide Default Values
Provide Default Values
Handle missing variables gracefully - undefined variables evaluate to empty strings
Keep Branches Simple
Keep Branches Simple
Each branch should do one thing well. Complex logic should be in separate functions.
Test Both Branches
Test Both Branches
Always test both the true and false paths of your conditions
Related
Nested Workflows
Combine patterns for complex pipelines
Workflow Routing
Route based on output content
Workflow Loops
Iterate over collections
YAML Workflows
Define workflows in YAML format

