Loop on Items

The Loop on Items component in ZBrain Flow automates the execution of a defined sequence of actions for each item in a structured array. This allows you to process records (such as data entries or rows), files, documents, or responses one by one without manual intervention or custom code, making it ideal for scenarios like batch data processing, extracting document text, sending bulk notifications, or handling nested data structures. Iteration starts from the first item in the array (index 0).

How to Use the Loop on Items Component in ZBrain Flow

Step 1: Add the Loop on Items Piece

  • Click the ‘+’ button in your flow and search for Loop on Items.

  • Select ‘Loop on Items’ from the component list to add it to your workflow.

Step 2: Configure Items to Iterate (Structured Array Required)

  • In the Loop on Items configuration panel, click the Items field.

  • Use the Data Selector to choose a structured array output from a relevant previous step in your flow (such as a webhook, file list, or JSON object). The Data Selector ensures you select a properly formatted list for iteration.

  • Once set, the Loop on Items component will automatically process each item in the array.

Step 3: Configure Downstream Actions

Once loop items are configured, the next step is to configure downstream actions that need to be executed for each item in the loop.

  • Configure the desired actions or components to the output of the Loop on Items component within your flow.

  • Each connected action will execute automatically for every item in the input array.

  • Optional: For multi-level or nested data processing, you can place another Loop on Items component inside the first one. This allows you to process nested or hierarchical data structures, such as handling arrays within arrays, like files within folders or line items within orders, by repeating the workflow for every sub-item.

Example: How Loop on Items Component Works

This simple example illustrates how the Loop on Items component operates within a larger workflow. Note that this covers only a portion of the overall agent’s workflow.

Suppose you have a PDF containing with technical diagrams and want to automatically extract the text from each page without manual effort. The Loop on Items component makes this possible by processing each page in a repeatable and automated manner.

How It Works in the Flow:

  1. Convert PDF to Images: The workflow first converts each page of the PDF into an individual image.

  2. Loop on Items: The Loop on Items component takes this array of images as input, where each item in the array is a single-page image. This component processes the images in order, starting from the first image in the array and continuing until the last. The component iterates over the array and, for each image, triggers the downstream actions below:

    • Extract Text Using AI Model: Each image is sent to an LLM with an appropriate prompt to extract content from the page.

    • Append Results: The extracted text is appended to storage, compiling the outputs for all pages.

By automating these steps for every page, Loop on Items ensures consistent and efficient document processing as part of a larger workflow, eliminating manual repetition and reducing errors.

Last updated