Documentation
HomeAPISign In
  • Getting Started
    • Overview
      • Core Concepts
      • Building your First Workflow
    • API Reference
  • Your Data
    • Brand Kits
    • Knowledge Bases
      • Add Data
        • Upload Files
        • Web Scrape
        • Import from Google Drive
        • Import from SQL Database
        • Import from Shopify
      • Knowledge Base Search
      • Knowledge Base Metadata
      • Knowledge Base API
  • Building Workflows
    • Workflow Concepts
      • Workflow Inputs
        • Input Types
      • Workflow Outputs
      • Variable Referencing
      • Liquid Templating
    • Workflow Steps
      • AI
        • Prompt LLM
          • Model Selection Guide
          • Prompting Guide
        • Transcribe Audio File
      • Web Research
        • Google Search
        • Web Page Scrape
      • Code
        • Run Code
        • Call API
        • Format JSON
        • Run SQL Query
        • Write Liquid Text
      • Flow
        • Condition
        • Iteration
        • Human Review
        • Content Comparison
        • Error
      • Data
        • Read from Grid
        • Write to Grid
        • Search Knowledge Base
        • Write to Knowledge Base
        • Get Knowledge Base File
      • AirOps
        • Workflow
        • Agent
      • Image & Video
        • Generate Image with API
        • Search Stock Images
        • Fetch Stock Image with ID
        • Resize Image
        • Screenshot from URL
        • Create OpenGraph Image
        • Create Video Avatar
      • SEO Research
        • Semrush
        • Data4SEO
      • Content Quality
        • Detect AI Content
        • Scan Content for Plagiarism
      • Content Processing
        • Convert Markdown to HTML
        • Convert PDF URL to Text
        • Group Keywords into Clusters
      • B2B Enrichment
        • Hunter.io
        • People Data Labs
      • CMS Integrations
        • Webflow
        • WordPress
        • Shopify
        • Contentful
        • Sanity
        • Strapi
      • Analytics Integrations
        • Google Search Console
      • Collaboration Integrations
        • Gmail
        • Google Docs
        • Google Sheets
        • Notion
        • Slack
    • Testing and Iteration
    • Publishing and Versioning
  • Running Workflows
    • Run Once
    • Run in Bulk (Grid)
    • Run via API
    • Run via Trigger
      • Incoming Webhook Trigger
      • Zapier
    • Run on a Schedule
    • Error Handling
  • Grids
    • Create a Grid
      • Import from Webflow
      • Import from Wordpress
      • Import from Semrush
      • Import from Google Search Console
    • Add Columns in the Grid
    • Run Workflows in the Grid
      • Add Workflow Column
      • Run Workflow Column
      • Map Workflow Outputs
      • Review Workflow Run Metadata
    • Review Content in the Grid
      • Review Markdown Content
      • Review HTML Content
      • Compare Content Difference
    • Publish to CMS from Grid
    • Pull Analytics in the Grid
    • Export as CSV
  • Copilot
    • Chat with Copilot
    • Edit Workflows with Copilot
    • Fix Errors with Copilot
  • Monitoring
    • Task Usage
    • Analytics
    • Alerts
    • Execution History
  • Your Workspace
    • Create a Workspace
    • Folders
    • Settings
    • Billing
    • Use your own LLM API Keys
    • Secrets
    • Team and Permissions
  • Chat Agents (Legacy)
    • Agent Quick Start
    • Chat Agents
    • Integrate Agents
      • Widget
      • Client Web SDK
  • About
    • Ethical AI and IP Production
    • Principles
    • Security and Compliance
Powered by GitBook
On this page
  • How does the Iteration Step work?
  • What is a list?
  • How do I generate a list?
  • Generating a list via an LLM Step
  • Generating a list via a Code Step
  • Generating a list via a Google Search Step
  • What is the element and element index?
  • How do I reference the element?
  • Is the element index required?
  • What does the output look like?
  • How do I turn the list into text?
  • Example

Was this helpful?

  1. Building Workflows
  2. Workflow Steps
  3. Flow

Iteration

Execute a step multiple times over a list of objects

Last updated 2 months ago

Was this helpful?

How does the Iteration Step work?

The Iteration Step executes the same step(s) over each entry within a list. The only prerequisite to using an Iteration Step is ensuring that your input values have already been formatted into a list object.

What is a list?

A list is a specific data type with elements separated by commas that begins with [ and ends with ] . For example:

A list of numbers:

[1,2,3,4,5]

A list of strings:

["sales", "marketing", "finance"]

A list of JSON objects:

[
  {
    "link": "https://openai.com/",
    "title": "OpenAI",
    "source": "OpenAI"
  },
  {
    "link": "https://www.youtube.com/@OpenAI",
    "title": "OpenAI",
    "source": "YouTube"
  },
  {
    "link": "https://en.wikipedia.org/wiki/OpenAI",
    "title": "OpenAI",
    "source": "Wikipedia"
  }
]

How do I generate a list?

Lists can be generated in multiple different ways, including through an LLM step, code step, Google Search or API step. It ultimately comes down to what works best for your use-case, and we've provide a few examples below to help.

Generating a list via an LLM Step

Because our LLM Steps allow you to adjust the prompt until you've achieved the desired outcome, it's a simple matter of specifying the list format within your prompt.

Let's walk through an example workflow that takes in a country name as input, and returns the top 5 cities in that country. We'll adjust the existing workflow to return those top 5 cities in a list format:

Generating a list via a Code Step

return(["San Francisco", "New York City", "Miami"]);

Generating a list via a Google Search Step

Our Google Search Step allows you to select the specific formatting of your resulting search:

The resulting output of the Google Search Step will be formatted like so:

// Output of the Google Search Step with Links Only
[
  "https://www.mckinsey.com/featured-insights/mckinsey-explainers/what-is-prompt-engineering",
  "https://www.zdnet.com/article/six-skills-you-need-to-become-an-ai-prompt-engineer/",
  "https://www.techtarget.com/searchenterpriseai/definition/AI-prompt-engineer",
  "https://en.wikipedia.org/wiki/Prompt_engineering",
  "https://www.datacamp.com/blog/what-is-prompt-engineering-the-future-of-ai-communication",
  "https://www.iit.edu/blog/unlock-career-opportunities-ai-how-become-ai-prompt-engineer",
  "https://aws.amazon.com/what-is/prompt-engineering/",
  "https://hbr.org/2023/06/ai-prompt-engineering-isnt-the-future",
  "https://time.com/6272103/ai-prompt-engineer-job/",
  "https://www.promptingguide.ai/"
]

What is the element and element index?

An element is the actual object/value (e.g. string, number, or object) in your list.

The element index is the position of the element within the list, starting with the first element at index 0.

How do I reference the element?

You can reference the element by clicking the pill step_x.element within your Iteration Step:

In the example above, the LLM step will run 3 times, and the {{step_1.element}] will be replaced with sales , marketing , and finance as such:

  • Give me 3 personas in the sales department

  • Give me 3 personas in the marketing department

  • Give me 3 personas in the finance department

Is the element index required?

The element index is optional, but it can be used to perform powerful logic.

For example, in the case of our SEO blog writer, we use the element_index to help us write our introductions. Because our goal is to have the writer only write to the first section of the blog, the element index is useful for only applying the step in that paragraph.

  • step_x.element_index == 0

which allows us to use a separate LLM Step with the introduction for the first section of the blog only.

What does the output look like?

The iteration step will also output a list.

The output of each iteration will be added to the list in the same order of the input.

How do I turn the list into text?

You can turn the array back into text with a simple Text step that uses Liquid:

// Replace step_x.output

{% for chunk in step_x.output %}
{{chunk}}
{% endfor %}

Example

Let's return to our example from earlier in this page, where our existing workflow now returns a list of the top 5 cities in a given country.

We're going to take this one step further, and use an Iteration Step to cycle through each of the cities, and perform an Image Generation Step of what each looks like:

The resulting output will give you 5 distinct images, one for each of the unique cities returned by your original LLM.

As our allows you to utilize both Javascript and Python, you can hard-code your return statement to match the desired list format, e.g.

So, we add a with:

Code Step
Conditional Step