loop() helper runs a step for each item in a list, CSV, or text file — ideal for batch processing and data pipelines.
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
Loop Over a List
2
Loop Over a CSV
3
Loop Over a Text File
Choosing an Iteration Source
Pick the parameter that matches where your items live.API Reference
loop()
Parameters
Context Variables
Inside the loop, these variables are available:Result Variables
After loop completion:Examples
Custom Variable Name
CSV with Headers
Givendata.csv:
With Agents
Chained Loops
Loop with Aggregation
Use Cases
How It Works
Best Practices
Handle errors per item
Handle errors per item
Catch exceptions inside the loop body so one bad row does not stop the entire batch.
Log progress on large files
Log progress on large files
Enable verbose mode or custom logging when iterating thousands of records.
Chunk very large datasets
Chunk very large datasets
Split massive CSVs into batches to limit memory and simplify retries.
Clean up resources in finally blocks
Clean up resources in finally blocks
Close files and connections even when individual items fail.
Error Handling
Related
Workflow Patterns
Overview of routing, parallel, loop, and repeat patterns
Workflow Routing
Decision-based branching in workflows
Workflow Parallel
Run independent steps concurrently
Workflow Repeat
Repeat steps until a condition is met

