> For the complete documentation index, see [llms.txt](https://docs.diaflow.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.diaflow.io/workflow-builder/nodes/built-in-tools/loop.md).

# Loop

## Loop

### What does it do?

The **Loop** node repeats the same workflow steps for each record in a list. Think of it like giving the same checklist to every row in a spreadsheet, then collecting the finished results in one place.

Use **Loop Output** at the end of the repeated steps. It gathers the values you want to keep from each pass.

#### Smart features

* **Accepts one record or many**: if you pass one record, Diaflow turns it into a one-item list and runs it once.
* **Checks the list before it starts**: Diaflow confirms the input is a valid list of records.
* **Starts with the first record automatically**: the workflow repeats the same path for each record in the list.
* **Collects one result per pass**: **Loop Output** saves the values you choose from each repeated run.
* **Cleans output field names for you**: selected paths like `{{loop.current.email}}` become output names such as `loop_current_email`.
* **Builds one final list at the end**: all saved results are combined into one structured output.

<figure><img src="/files/QBFQHktmoMtQtAEMzvt2" alt=""><figcaption></figcaption></figure>

### Real-World Business Value

* Send personalized follow-up emails to every lead in a contact list and save each send result.
* Review every support ticket in a daily batch, summarize it, and store the summary with the ticket ID.
* Process new product records one by one, enrich them with AI or app data, and return one clean list for export.

### Step-by-Step Setup

* Drag **Loop** onto the canvas.
* In **Input**, select the list you want to repeat over. Use a field from an earlier step with **@**.
* In **Batch size**, use it as a reference only. This value is currently fixed by Diaflow and cannot be changed in the node.
* In **On Error when running loop**, choose **Skip and record error** if you want the loop to continue, or **Stop workflow** if one failed item should stop everything.
* Place the nodes you want to repeat between **Loop Over Items** and **Loop Output**.
* In those repeated nodes, use values from the current record, such as `{{loop.current.email}}` or `{{loop.current.name}}`.
* In **Loop Output**, add each value you want to save from every pass.
* Run the workflow once and review the **Output** tab to confirm the saved fields look right.

### Loop Output details

**Loop Output** is the save point at the end of your repeated steps. It decides which values from each pass should be kept in the final result.

Think of it like a results sheet. Each time the loop runs, **Loop Output** adds one new row with the values you selected.

#### What it stores

Add one or more values in **Loop Output**.

You can store:

* a value from the current record, such as `{{loop.current.email}}`
* a result from a node inside the loop, such as `{{email_sender.data.message_id}}`
* several values together, so each pass returns one complete record

#### How field names are created

Diaflow creates output names automatically from the values you select.

For example:

* `{{loop.current.email}}` becomes `loop_current_email`
* `{{loop.current.id}}` becomes `loop_current_id`
* `{{email_sender.data.message_id}}` becomes `email_sender_data_message_id`

This helps keep the final output structured and reusable in later steps.

#### What one saved result looks like

If one pass through the loop sends an email and stores the contact email plus the send ID, the saved result looks like this:

```json
[
  {
    "loop_current_email": "alice@acme.com",
    "email_sender_data_message_id": "msg_001"
  }
]
```

After the loop finishes all passes, Diaflow combines those saved results into one final list.

#### Best way to configure it

* In **Loop Output**, add only the fields you truly need later.
* Start with 2 or 3 fields for your first test.
* Use values from inside the loop, not from unrelated nodes outside it.
* Run the workflow once and confirm each saved field has a real value.

{% hint style="info" %}
If a selected value cannot be found, the final result may contain an empty value. Test once before publishing.
{% endhint %}

### The Transformation: Before & After

**Before list entering the Loop node**

<figure><img src="/files/Qv6JXcVrBLtCQG052hps" alt=""><figcaption></figcaption></figure>

**After final result collected by Loop Output**

<figure><img src="/files/LOh1AE9CDVGYPQMCGMBz" alt=""><figcaption></figcaption></figure>

### Tips & Warnings for First-Timers

#### Best practices

* Keep the input list to **100 records or fewer**.
* Pass a list of records with named fields, not a list of plain values.
* If you only have one record, you can still use **Loop**. Diaflow will run it once.
* Test **Loop Output** once before publishing. Confirm every saved field contains a real value.
* Keep your saved field references consistent. Clear node names make the final output easier to read.

#### Warnings

* Do not pass an empty list. The loop will fail instead of skipping cleanly.
* Do not pass plain values like `["a", "b"]` or `[1, 2, 3]`. Wrap each value in a record first.
* Do not expect more than the first **100** records to run. Extra records are ignored.
* Do not use broken or incomplete field references in **Loop Output**. You may get empty results without a warning.
* Do not assume the final output is a single record. The result is a list of saved results, with one item per pass.

### Need help?

* Learn the basics in [How a node works](/getting-started/lets-start-with-the-basics/how-a-node-works.md)
* Build the full flow in [Create a workflow](/workflow-builder/create-a-workflow.md)
* Browse related nodes in [Component List](/workflow-builder/component-list.md)
