AutomationFlowsAI & RAG › Loop Over Items with AI for LinkedIn Captions

Loop Over Items with AI for LinkedIn Captions

Original n8n title: Loop Over Items — Beginner Example

ByRobert Breen @rbreen on n8n.io

This workflow introduces beginners to one of the most fundamental concepts in n8n: looping over items. Using a simple use case—generating LinkedIn captions for content ideas—it demonstrates how to split a dataset into individual items, process them with AI, and collect the…

Event trigger★★★★☆ complexityAI-powered8 nodesOpenAI ChatTool ThinkAgent
AI & RAG Trigger: Event Nodes: 8 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #7152 — we link there as the canonical source.

This workflow follows the Agent → OpenAI Chat recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "bdd87769-9f12-4bd1-8dd9-1b90ec218209",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        600,
        -540
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "6209e2d5-4c6e-4239-8275-a8d3411cb6f9",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        820,
        -120
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "8e3ecba2-5a55-40bc-ba3a-b3cb0d581630",
      "name": "Tool: Inject Creativity",
      "type": "@n8n/n8n-nodes-langchain.toolThink",
      "position": [
        1060,
        -100
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "a73bc4ac-78f7-4410-ac1a-0952415dbe9f",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -740,
        -900
      ],
      "parameters": {
        "width": 2260,
        "height": 1140,
        "content": "## \ud83d\udcec Need Help or Want to Customize This?\n\ud83d\udce7 [robert@ynteractive.com](mailto:robert@ynteractive.com)  \n\ud83d\udd17 [LinkedIn](https://www.linkedin.com/in/robert-breen-29429625/)\n\n\n## \ud83d\udd27 Step-by-Step Setup\n\n### 1\ufe0f\u20e3 Run Workflow\n\n- **Node**: `Manual Trigger (Run Workflow)`\n- **Purpose**: Manually start the workflow for testing or learning.\n\n\n### 2\ufe0f\u20e3 Create Random Data\n\n- **Node**: `Create Random Data (Code)`\n- **What it does**: Simulates incoming data with multiple content ideas.\n\n\n### 3\ufe0f\u20e3 Loop Over Items\n\n- **Node**: `Loop Over Items (SplitInBatches)`\n- **Purpose**: Sends one record at a time to the next node.\n- **Why It Matters**: Loops in n8n are created using this node when you want to iterate over multiple items.\n\n\n### 4\ufe0f\u20e3 Create Captions with AI\n\n- **Node**: `Create Captions (LangChain Agent)`\n- **Prompt**: \n```text\nidea: {{ $json.idea }}\n```\n- **System Message**: \n```text\nYou are a helpful assistant creating captions for a LinkedIn post. Please create a LinkedIn caption for the idea.\n```\n- **Model**: GPT-4o Mini or GPT-3.5\n- **Credentials Required**:\n  - **OpenAI Credential**  \n    - Go to: [OpenAI API Keys](https://platform.openai.com/account/api-keys)\n    - Create a key and add it in n8n under credentials as \u201cOpenAi account\u201d\n\n\n### 5\ufe0f\u20e3 Inject Creativity (Optional)\n\n- **Node**: `Tool: Inject Creativity (LangChain Tool)`\n- **Purpose**: Demonstrates optional LangChain tools that can enhance or manipulate input/output.\n- **Why It\u2019s Cool**: A great way to show chaining tools to AI agents.\n\n\n\n\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "a523d13f-653d-4a91-a672-b0bd5d558f27",
      "name": "Run Workflow",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        220,
        -680
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "f0e1af9b-2785-47b1-a38c-3e108bff67f8",
      "name": "Create Random Data",
      "type": "n8n-nodes-base.code",
      "position": [
        380,
        -540
      ],
      "parameters": {
        "jsCode": "return [\n  {\n    json: {\n      row_number: 2,\n      id: 1,\n      Date: '2025-07-30',\n      idea: 'n8n rises to the top',\n      caption: '',\n      complete: ''\n    }\n  },\n  {\n    json: {\n      row_number: 3,\n      id: 2,\n      Date: '2025-07-31',\n      idea: 'n8n nodes',\n      caption: '',\n      complete: ''\n    }\n  },\n  {\n    json: {\n      row_number: 4,\n      id: 3,\n      Date: '2025-08-01',\n      idea: 'n8n use cases for marketing',\n      caption: '',\n      complete: ''\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "8891b681-a7cf-44c0-aff7-79e7774120d1",
      "name": "Create Captions",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        860,
        -380
      ],
      "parameters": {
        "text": "=idea: {{ $json.idea }}",
        "options": {
          "systemMessage": "You are a helpful assistant creating captions for a linkedin post. Please create a linkedin caption for the idea. "
        },
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "fa53cf32-03de-4667-80bb-b28f8c3a16aa",
      "name": "Output Table",
      "type": "n8n-nodes-base.set",
      "position": [
        960,
        -600
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "331d2ca1-da0d-41ec-ac82-abe78052b84c",
              "name": "idea",
              "type": "string",
              "value": "={{ $('Create Random Data').item.json.idea }}"
            },
            {
              "id": "019369d9-ae99-4c29-b31d-013e29c4fdb6",
              "name": "output",
              "type": "string",
              "value": "={{ $json.output }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    }
  ],
  "connections": {
    "Run Workflow": {
      "main": [
        [
          {
            "node": "Create Random Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Captions": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Output Table",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Captions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Create Captions",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Create Random Data": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Tool: Inject Creativity": {
      "ai_tool": [
        [
          {
            "node": "Create Captions",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

This workflow introduces beginners to one of the most fundamental concepts in n8n: looping over items. Using a simple use case—generating LinkedIn captions for content ideas—it demonstrates how to split a dataset into individual items, process them with AI, and collect the…

Source: https://n8n.io/workflows/7152/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

🎯 Create viral TikToks, Shorts, Reels, podcasts, and ASMR videos in minutes — all on autopilot.

OpenAI, HTTP Request, Form Trigger +7
AI & RAG

Generate AI viral videos with NanoBanana & VEO3, shared on socials via Blotato 2. Uses @blotato/n8n-nodes-blotato, googleSheets, lmChatOpenAi, toolThink. Event-driven trigger; 94 nodes.

@Blotato/N8N Nodes Blotato, Google Sheets, OpenAI Chat +9
AI & RAG

Jarvis is a powerful multi-agent productivity assistant built in n8n. It works directly from Telegram and can understand both text messages and voice notes.

Telegram Trigger, Telegram, OpenAI +10
AI & RAG

This template is designed for marketers, content creators, and e-commerce brands who want to automate the creation of professional ad videos at scale. It’s ideal for teams looking to generate consiste

Telegram, Telegram Trigger, Google Drive +8
AI & RAG

This n8n template automates B2B lead research and enrichment for Attio CRM. It combines data from Apollo.io, LinkedIn scraping, and news sources with AI-powered analysis to generate actionable sales i

HTTP Request, N8N Nodes Scrape Creators, @Tavily/N8N Nodes Tavily +5