Skip to main content
Conditional branching lets you create dynamic workflows that take different paths based on runtime conditions. Use the 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.
The user triggers a flow; conditions pick the next step from runtime values.

Quick Start

1

Python or YAML

Condition Syntax

Numeric Comparisons

>, <, >=, <=, ==, !=

String Equality

==, != for exact matches

Contains Check

in or contains keywords

Boolean Values

true, false for flags

Numeric 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

The else_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:

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
string
required
Condition expression with {{variable}} placeholders
then_steps
list
required
Steps to execute when condition is true
else_steps
list
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

Make conditions readable: {{user.is_verified}} == true is clearer than {{v}} == 1
Handle missing variables gracefully - undefined variables evaluate to empty strings
Each branch should do one thing well. Complex logic should be in separate functions.
Always test both the true and false paths of your conditions

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