Skip to main content
The 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.
The user triggers a batch job; each list item runs through the loop step.

Quick Start

1

Loop Over a List

Output:
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

Given data.csv:

With Agents

Chained Loops

Loop with Aggregation

Use Cases

How It Works


Best Practices

Catch exceptions inside the loop body so one bad row does not stop the entire batch.
Enable verbose mode or custom logging when iterating thousands of records.
Split massive CSVs into batches to limit memory and simplify retries.
Close files and connections even when individual items fail.

Error Handling

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