Skip to main content

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.

Why This Matters

Manually processing lists is tedious and not scalable. For Each automates the repetition so workflows stay simple and reliable, whether the list has 3 items or 3,000.

Step 1: Provide the Input Array

The component expects a single input: a JSON array.

InputRequired?DescriptionNotes
ArrayYesItems to process one by oneMust be a valid JSON array such as [1,2,3], ["a","b"], or an array of objects
Dynamic Sources

Pass arrays from API Call, Code, Database, or any previous step that returns a list.

Step 2: Build the Loop Steps

Inside For Each, add the components that should run for each item. Two loop variables are available:

VariableDescription
itemThe current list value such as "alice" or { "id": 42, "email": "[email protected]" }
indexPosition 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.

OutputDescriptionData Shape
ResultAll collected outcomes from the loopDepends 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."
]
Send Results Forward

Connect Result to downstream steps such as Code, RAG Remember, or another For Each.

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.

Troubleshooting

Common Causes and Fixes
  • Not an array
    Ensure the input is a valid JSON array. Log it with Code if unsure.
  • Wrong field path
    Verify object access such as {{item.email}} matches the actual input.
  • Unexpected Result shape
    Remember the final value comes from the last step inside the loop. Confirm that step outputs what you need.
  • Nothing returned
    Check that the loop ran at least once and the array was not empty.

What To Try Next

  • Enrich each item with an API Call and return only the needed fields with Array Only.
  • Pipe the Result into GenAI LLM to summarise the list in one paragraph.
  • Chain a second For Each to post process only the items that met a condition in the first pass.