Workflow Routing
Route workflows to different paths based on the output of a decision step. This pattern is also known as Agentic Routing or Conditional Branching.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
Define classifier and handlers
2
Route by classifier output
API Reference
route()
Parameters
How Matching Works
The router checks if any route key (case-insensitive) is contained in the previous step’s output:Examples
Multi-Step Routes
Each route can contain multiple steps:Chained Routing
Routes can be chained for complex decision trees:With Agents
Routes can include Agent instances:Use Cases
How It Works
Best Practices
Always include a default route
Always include a default route
Handle unexpected classifier output gracefully instead of failing the workflow.
Use unambiguous route keys
Use unambiguous route keys
Short, distinct keys reduce mis-routing when LLM output is noisy.
Keep each route focused
Keep each route focused
One clear purpose per branch simplifies testing and observability.
Log routing decisions
Log routing decisions
Record which route was taken to debug triage and moderation pipelines.
Related
Workflow Patterns
Overview of routing, parallel, loop, and repeat
Workflow Parallel
Run independent steps concurrently
Workflow Loop
Iterate over lists and files
Workflow Repeat
Repeat until a condition is met

