For Each Component
For Each runs a set of steps for every item in an array, then returns one aggregated result. Use it to process batch data, transform lists, or run repeatable tasks in sequence.
Step 1: Provide the Input Array
The component expects a single input: a JSON array.
| Input | Required? | Description | Notes |
|---|---|---|---|
| Array | Yes | Items to process one by one | Must be a valid JSON array such as [1,2,3], ["a","b"], or an array of objects |
Step 2: Build the Loop Steps
Inside For Each, add the components that should run for each item. Two loop variables are available:
| Variable | Description |
|---|---|
| item | The current list value such as "alice" or { "id": 42, "email": "[email protected]" } |
| index | Position of the current item starting at 0 |
Use {{item}} and {{index}} as inputs to components inside the loop.
For objects, access fields like {{item.email}} or {{item.id}}.
Example input
[
{ "id": 101, "email": "[email protected]" },
{ "id": 102, "email": "[email protected]" }
]
Example use inside the loop
- API path:
/users/{{item.id}} - Email field to validate:
{{item.email}}
Step 3: Choose the Output Format
This controls the structure of the final Result after all iterations finish.
Full returns an object per iteration with index, item, and the full output of the last step inside the loop.
Good for debugging and audits.
[
{ "index": 0, "item": "apple", "result": { "status": 200, "value": "processed_apple" } },
{ "index": 1, "item": "banana", "result": { "status": 200, "value": "processed_banana" } }
]
Step 4: Use the Aggregated Result
For Each exposes one output after the loop completes.
| Output | Description | Data Shape |
|---|---|---|
| Result | All collected outcomes from the loop | Depends on the selected Output Format |
End to end example
Input
[
"Ada Lovelace",
"Alan Turing"
]
Loop step inside For Each
- LLM prompt:
Summarise "{{item}}" in one sentence.
Output with Array Only
[
"Ada Lovelace pioneered early computing concepts.",
"Alan Turing shaped modern computer science and cryptography."
]
Best Practices
- Keep Loop Steps Focused
Use small, single-purpose steps inside the loop. Move heavy logic to a reusable Agent Skill or Code step. - Guard Against Empty Lists
Add a Condition before For Each to skip execution when the array is empty. - Mind API Limits
If calling external APIs, consider rate limits. Add retries or spacing where needed. - Choose the Right Output
Use Array Only for transforms, Minimal for light tracking, Full for traceability and audits.