> For the complete documentation index, see [llms.txt](https://docs.stackai.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stackai.com/guides-and-quickstarts/workflow-builder/loops-and-reusable-project-calls.md).

# Loops and reusable project calls

Loops repeat a process for the items in a list. Use Loop Subflow to repeat a connected group of nodes. Use a project node's Loop Mode to run an existing workflow for several inputs.

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQ1Sgy933krTyK0S4JpP%2Fuploads%2FCiE9Os0wqMJGybJ6Y258%2FG025.mp4?alt=media&token=1fbc22ee-8e79-4cc8-b42f-7fb484e30101>" %}

## Repeat steps for each list item

Connect the Loop branch to the work required for each item and the Done branch to the final output.

![Loop and Done branch connections](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/NUCQKG40dNJVmEVPHQYq/assets/g025-g025-01-loop-canvas.png)

These branches serve different stages of the loop.

Set Loop Data to a list of items.

![Loop Data list input](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/l3HG1JmvYuYH0cAuSXzC/assets/g025-g025-02-loop-data.png)

Supply an array rather than a single text value that only looks like a list. For example, `["first item", "second item"]` is a JSON array with two items. The text `first item, second item` is one text value. Typing brackets into a text input alone does not guarantee that the result is an array.

Use a reference to a field that appears as a list in the upstream results. If the list is generated by a model, configure an array field with [Structured outputs and templates](https://docs.stackai.com/guides-and-quickstarts/workflow-builder/structured-outputs-and-templates.md). Run the upstream node, expand the field to confirm that it contains separate items, and use [Map variables and expressions](https://docs.stackai.com/guides-and-quickstarts/workflow-builder/map-variables-and-expressions.md) to select that field for **Loop Data**.

In the per-item step, insert Loop Subflow → current\_item.

![Current-item reference in a per-item step](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/BkVF781r9J0QtefVG9rg/assets/g025-g025-03-current-item.png)

This reference supplies the item being processed during the current iteration.

Run the workflow and inspect the collected results.

![Collected loop results](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/C40yq0qEeeA5PKthRjzV/assets/g025-g025-04-loop-result.png)

Check that each input item has the expected corresponding result.

## Call an existing workflow

In a project-calling node, select the workflow you want to reuse.

![Selection of a workflow to reuse](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/e7kwiRqiidMpL80mzcf2/assets/g025-g025-05-project-target.png)

Start with Loop Mode set to No when passing a single input.

Map the selected workflow's required input to a live value from the calling workflow.

![Required input mapped into a project call](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/m8Sz9OUloFD83aGY902u/assets/g025-g025-06-project-input.png)

The value must match what the selected workflow expects to receive.

Run the caller and inspect the returned output structure.

![Returned project-call output structure](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/5G8HdR0oCEiYoy6D52FQ/assets/g025-g025-07-project-single.png)

Use the actual output fields when connecting the result to later nodes.

## Call the workflow for a list

Set Loop Mode to Yes to pass a list of inputs.

![Loop Mode enabled for a list of inputs](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/cMtqxpFE8k9vvbyamuHW/assets/g025-g025-08-project-loop-input.png)

Each item must satisfy the selected workflow's input requirements.

Run the list and inspect the collected responses.

![Collected responses from repeated project calls](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/yLuPrEqwvBVoUQf2decZ/assets/g025-g025-09-project-loop-result.png)

Confirm that the returned results correspond to the supplied items before passing them onward.

## Important behavior

The original project node processes list items one at a time. The Beta node can process independent items together.

If the repeated operation changes external records, each list item can cause a separate change.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.stackai.com/guides-and-quickstarts/workflow-builder/loops-and-reusable-project-calls.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
