AI Content Caption Generator with Looping Logic - n8n Workflow

Use this powerful n8n workflow template to generate social media captions using OpenAI/GPT-4o mini, demonstrating how to loop over multiple items using the critical n8n node Split In Batches.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Content Marketing Managers needing to quickly draft multiple social media posts.
Automation specialists looking for practical examples of core logic flow control in an n8n workflow.
Users interested in chaining advanced LangChain tools with the OpenAI n8n node.
Beginners seeking clear n8n templates demonstrating how to structure a loop using the Split In Batches n8n node.

Overview

This comprehensive n8n workflow is designed to handle bulk content creation by efficiently processing a list of ideas using artificial intelligence. The primary challenge addressed here is ensuring that an AI agent processes each incoming item individually, a requirement often necessary for maintaining context and quality. By leveraging the 'Loop Over Items' n8n node (Split In Batches), this n8n template ensures scalability.

After generating simulated data containing several content ideas, the n8n workflow isolates each idea and passes it sequentially to the LangChain Agent. This agent, powered by the GPT-4o Mini OpenAI Chat Model, acts as a helpful assistant to create tailored LinkedIn captions. This demonstration not only showcases potent AI integration but also provides an essential pattern for structuring any large-scale data processing task within n8n.

How it Works

The entire process is initiated by the Run Workflow n8n trigger, which allows for manual testing or scheduled execution.


  1. Data Generation: The Create Random Data Code n8n node simulates incoming input, generating a predefined list of three content ideas related to 'n8n'.

  2. Loop Initiation: The data stream flows into the Loop Over Items (Split In Batches) n8n node. This essential flow control n8n node splits the batch of ideas into individual items, ensuring that the downstream AI process handles them one by one.

  3. AI Processing: For each item, the flow proceeds to the Create Captions n8n node, which acts as a LangChain Agent. This agent uses the OpenAI Chat Model (GPT-4o-mini) to generate a unique caption based on the input idea, following a specific system instruction (to be a helpful LinkedIn caption assistant).

  4. Tool Chaining (Optional): The Tool: Inject Creativity n8n node is connected to the agent, demonstrating how optional tools can be chained to an AI agent to enhance or manipulate the agent's behavior during execution—a powerful feature of the LangChain n8n integration.

  5. Result Collection: Finally, the Output Table Set n8n node runs after the entire loop completes, compiling the original ideas alongside the new AI-generated output for a consolidated final result, completing this robust n8n workflow.

Installation Guide

To utilize this n8n workflow template, follow these steps:


  1. Import the JSON: Copy the provided n8n workflow JSON data and paste it into your n8n instance using the 'Import Workflow' option.

  2. OpenAI Credentials: This workflow requires valid OpenAI credentials. Click on the OpenAI Chat Model n8n node and set up a new credential named 'OpenAi account' (or update the existing connection).

Obtain your API Key from the OpenAI platform.
Ensure the key is active and has necessary permissions.

  1. Test Run: Initiate the workflow using the Run Workflow n8n trigger to generate the sample data and observe the looping and AI processing in action. The Output Table n8n node will display the final generated captions.

Node Details

Run Workflow (Manual Trigger): The initial n8n trigger. Used for manually starting and testing this specific n8n workflow.
Create Random Data (Code n8n node): Generates static sample data containing a list of content ideas (e.g., 'n8n rises to the top', 'n8n use cases for marketing') to simulate real input data for the n8n workflow.
Loop Over Items (Split In Batches n8n node): The core flow control mechanism. This critical n8n node splits the incoming array of data into batches of one, allowing the subsequent AI nodes to process each item individually within the n8n workflow loop.
Create Captions (LangChain Agent n8n node): The primary generative component. It takes the individual idea from the loop and uses the connected language model to generate a LinkedIn caption based on the defined system prompt.
OpenAI Chat Model (LangChain n8n node): Configures the AI model used by the agent, specifically set to the efficient 'gpt-4o-mini'. This node requires a functional OpenAI API credential.
Tool: Inject Creativity (LangChain Tool n8n node): An optional n8n node demonstrating tool utilization with the Agent. It enhances the agent’s capabilities, providing a more complex AI execution path.


  • Output Table (Set n8n node): Gathers the results after the looping process. It collects the original idea (using expressions referencing the Create Random Data n8n node) and the final AI output (the generated caption).

Related n8n Workflows

Free

Nodes: 8 Nodes
Updated: December 26 2025
View all
Created by

Professional services consultant with over 10 years of experience solving complex business problems across industries. I specialize in n8n and process automation—designing custom workflows that integrate tools like Google Calendar, Airtable, GPT, and internal systems. Whether you need to automate scheduling, sync data, or streamline operations, I build solutions that save time and drive results.

Featured*