n8n Data Pipelines Explained: Split Out, Aggregate, Switch, Loops and AI Agents on Real Workflows
Reports, invoices and data exports are lists inside lists. To automate them you need a few data-shaping nodes: split a list apart, work on each line, group the results again, route them, and loop when a job is too big. Here's what each one does, shown on real pipelines from our portfolio and then applied to everyday business tasks.
Short answer
In n8n, data moves as a list of items, and most nodes run once per item.[1][2] Split Out turns one list (an order's products) into separate items;[3] Aggregate puts items back into one;[4] Summarize groups and totals them like a pivot table.[5] If, Switch and Filter decide where each item goes; Loop Over Items processes big lists in batches;[6] sub-workflows split a big job into modular pieces;[7] and an AI Agent with tools lets people ask questions about the result in plain language.[8]
Real workflow: a sales data pipeline with three outputs
View “Sales Data Pipeline” on GitHub ↗What it does. This workflow was built on the training dataset of n8n's official course, so it uses the same data shapes as real e-commerce exports.[9] It downloads a sales file containing a list of orders. It splits the list into one item per order and keeps the fields that matter. Then it produces three results: all orders sent to a data warehouse, a summary of delivered orders by region (total, count, average), and the same summary as a CSV file with a timestamp.
Notice that one node's output can feed several branches at once. The order list feeds both the raw export and the regional analysis, so one download serves three audiences. In a real business, you would replace the manual start with a schedule or webhook trigger.
Split Out, Aggregate, Summarize: the shape-shifters
If you've read how JSON works, you know a file can contain a list inside a field, such as one sales file with fifty orders, or one invoice with eight product lines. These nodes change how many items you have, without changing the data itself.
| Node | What it does | Items in → out | Everyday example |
|---|---|---|---|
| Split Out | Takes a list inside one item and makes one item per entry[3] | 1 → many | One invoice → one item per product line, so each line can be checked against stock |
| Edit Fields (Set) | Keeps, renames or calculates fields on each item[10] | many → many | Add “price × quantity” to every line |
| Aggregate | Groups separate items, or chosen fields, into one item[4] | many → 1 | Collect all lines into one pick list for the warehouse |
| Summarize | Totals, counts or averages items, optionally per group, like a pivot table[5] | many → one per group | Revenue and order count per region or per salesperson |
| Rename Keys | Renames field names[11] | many → many | Turn technical names into the ones your accountant's sheet expects |
| Convert to File | Turns items into a CSV, Excel or other file[12] | many → 1 file | Attach a weekly CSV to an email or upload it to Drive |
The rule of thumb: split when you need to look at each line (check, enrich, route), and aggregate or summarize when the next system wants one message (one API call, one email, one row). The maintenance-company example in part 2 uses exactly this pair: Split Out on the parts and hours of a job report, then Aggregate into one invoice.
If, Switch, Filter, Stop And Error: routing decisions
- Filter keeps matching items and drops the rest. Use it when the others don't matter, such as orders that aren't paid yet.[13]
- If splits items into a true and a false branch. Use it when both sides need handling, for example delivered orders to the analysis and the others to a follow-up.[14]
- Switch sends items to one of many routes based on rules, with an optional fallback.[15] Typical uses: support tickets by language, orders by country to different couriers, files by type.
- Stop And Error deliberately fails the run with your own message, which also fires the error workflow.[16][17]
Real workflow: a healthcare CSV pipeline that adapts itself
View “Healthcare CSV Ingestion & Cleaning” on GitHub ↗What it does. This is our most complete pipeline, built on public hospital datasets.[9] When a CSV lands in a Google Drive folder, the workflow checks the file's size. Small files are downloaded, cut into chunks and inserted into a MySQL database. Large files go to the self-calling webhook from part 2, which streams them in 2 MB slices. A Switch node then recognises the dataset type from its columns: cardiology admissions, hospital-level data or weekly respiratory data. Each type gets its own cleaning and KPI queries. Unknown formats go to a fallback route that calls an auto-adapt sub-workflow. It infers the column types, creates the tables, cleans the data, and emails a warning if some columns are ambiguous.
Sub-workflows: build a step once, use it everywhere
The auto-adapt step is a separate workflow that starts with an Execute Sub-workflow Trigger. Both the normal pipeline and the streaming webhook call it with the Execute Sub-workflow node.[18][19] n8n's documentation describes sub-workflows as a way to build modular, “microservice-like” workflows, which also helps when a workflow grows too large for memory.[7] For a business, that means one “clean customer file” or “create invoice” step shared by every workflow that needs it, so a fix happens in one place.
Where else this pattern fits
- Retail: each supplier sends price lists in a different format; a Switch on the column names routes each one to the right cleaning step before prices update.
- Accounting: bank exports land in a folder; transactions are stored, categorised and summed per month without opening a spreadsheet.
- HR: monthly timesheet exports are checked, and any row with impossible hours triggers Stop And Error and an alert to the manager.
Looping in n8n: three ways, and when to use each
People coming from spreadsheets or code often look for a “for each” block. In n8n you rarely need one, because nodes already run once for every incoming item.[2]
| Approach | How it works | Use it when |
|---|---|---|
| Built-in | Each node processes every item automatically[2] | Most cases: send 50 emails, update 200 rows |
| Loop Over Items | Sends items through in batches of a size you choose; add a Wait node to pause between batches[6][20] | An API has a rate limit, or each item needs several steps before the next starts |
| Manual loop | Connect an output back to an earlier node and stop with an If node[2] | Paging through an API until there are no more pages |
| Self-calling webhook | Each run ends by calling its own webhook with the next position | Very long jobs that should run as many small executions, like our large-file stream[9] |
The documentation lists a few exceptions where n8n does not loop for you. For example, the HTTP Request node doesn't page through results by itself, and the Code node in “run once for all items” mode receives everything at once.[2]
Real workflows: AI agents that answer from your data
View “Data Analytics Agent (Slack)” on GitHub ↗What it does. Once the healthcare data is clean, anyone on the team can ask a question in Slack, for example “average length of stay for emergency admissions in March?”, and get the answer in the same thread.[9] The agent has two tools, both small sub-workflows: one lists the available tables and their columns, and one runs a database query. Its memory is keyed to the Slack thread, so follow-up questions keep their context.
- AI Agent: the model reads the question, decides which tool to call, reads the result and writes the answer.[8]
- Call n8n Workflow Tool: turns any sub-workflow into a tool the agent can use, with a description that tells the model when to use it.[21]
- Simple Memory: keeps the last messages of a conversation. Using the Slack thread as the key gives each discussion its own memory.[22][23]
A second, smaller agent from the same n8n course dataset handles customer service in a chat window. It uses a Data Table tool to look up customers and an HTTP Request Tool to fetch order details.[24][25][26] The pattern is the same: a trigger where people already talk, an agent, and tools limited to the data it needs.
OWASP lists prompt injection and excessive agency among the top risks of LLM applications.[27] That's why the query tool starts with an If node that rejects anything other than a single read-only SELECT. Add a database user with read-only rights too, the least-privilege defence OWASP recommends against SQL misuse.[28] Our guide to securing AI agents covers this in depth.
Why it matters: in a 2025 study of 5,172 customer-support agents, an AI assistant increased issues resolved per hour by 15% on average, with the biggest improvements for less experienced workers.[29] An internal data assistant applies the same idea to every colleague who used to wait for “the person who knows SQL”.
Apply it: five everyday business pipelines
| Manual task today | Pipeline | Key nodes |
|---|---|---|
| Typing an invoice after every repair job | Job-report form → one line per part → one invoice to the customer | Form Trigger, Split Out, Edit Fields, Aggregate, HTTP Request |
| Monday sales report in Excel | Shop API → delivered orders → totals per region and category → CSV by email | Schedule, If, Summarize, Convert to File, Gmail |
| Reformatting supplier price lists | New file in Drive → detect supplier format → clean → update catalogue | Drive Trigger, Switch, sub-workflow, Stop And Error |
| Updating 5,000 product prices | Read catalogue → batches of 100 → update via API → wait between batches | Loop Over Items, HTTP Request, Wait |
| “Can you pull the numbers for…?” messages | Slack question → agent with read-only query tool → answer in thread | Slack Trigger, AI Agent, Workflow Tool, Memory |
Each of these replaces a weekly or daily routine with one that runs on its own and only asks for attention when something is wrong. Add the error-alert workflow from part 2, and for outreach and reporting ideas see part 3 on lead generation and marketing reports.
Frequently asked questions
What is the difference between Split Out and Loop Over Items in n8n?
Split Out changes the shape of your data: it turns a list inside one item into separate items.[3] Loop Over Items doesn't change the data; it controls the pace, sending existing items through in batches.[6] You often use Split Out first, then let nodes process each item automatically.
When should I use Aggregate instead of Summarize?
Use Aggregate to collect items into one item, for example a list of lines for a single API call or email.[4] Use Summarize when you need numbers such as sums, counts or averages, optionally grouped by a field like region.[5]
Do I need the Loop Over Items node to process every row?
Usually not. n8n nodes already run once for each incoming item.[2] Use Loop Over Items when you must respect an API rate limit or process items in batches, and add a Wait node between batches if needed.[6][20]
What is a sub-workflow in n8n?
A sub-workflow is a separate workflow that starts with the Execute Sub-workflow Trigger and is called by other workflows through the Execute Sub-workflow node.[19][18] It lets you keep workflows modular, so a step such as cleaning a file is built once and called wherever it's needed.[7]
Is it safe to let an AI agent query my database?
It can be, if the agent's power is limited. Give it only the tools it needs, check every query (for example, SELECT-only), and connect with a read-only database user.[28] OWASP lists prompt injection and excessive agency among the top LLM risks, so keep a human in charge of anything that changes data.[27]
Sources
Every explanation in this article is based on the technical standards, official documentation, peer-reviewed research and real workflows listed below. Numbers in the text, such as [1], link to the matching source and open this list. All links were checked on October 28, 2026.
Show all 29 sourcesHide sources
- n8n Docs. Data structure (items). Official n8n documentation. docs.n8n.io/data/data-structure/
- n8n Docs. Looping in n8n. Official n8n documentation. docs.n8n.io/flow-logic/looping/
- n8n Docs. Split Out node. Official n8n documentation. docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.splitout/
- n8n Docs. Aggregate node. Official n8n documentation. docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.aggregate/
- n8n Docs. Summarize node. Official n8n documentation. docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.summarize/
- n8n Docs. Loop Over Items (Split in Batches) node. Official n8n documentation. docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.splitinbatches/
- n8n Docs. Sub-workflows. Official n8n documentation. docs.n8n.io/flow-logic/subworkflows/
- n8n Docs. AI Agent node. Official n8n documentation. docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/
- Meddeb, Y. (2026). n8n-workflows: portfolio of production and training n8n workflows (exported JSON). GitHub repository. github.com/yahmed-web/n8n-workflows
- n8n Docs. Edit Fields (Set) node. Official n8n documentation. docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.set/
- n8n Docs. Rename Keys node. Official n8n documentation. docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.renamekeys/
- n8n Docs. Convert to File node. Official n8n documentation. docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.converttofile/
- n8n Docs. Filter node. Official n8n documentation. docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.filter/
- n8n Docs. If node. Official n8n documentation. docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.if/
- n8n Docs. Switch node. Official n8n documentation. docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.switch/
- n8n Docs. Stop And Error node. Official n8n documentation. docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.stopanderror/
- n8n Docs. Error handling. Official n8n documentation. docs.n8n.io/flow-logic/error-handling/
- n8n Docs. Execute Sub-workflow node. Official n8n documentation. docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.executeworkflow/
- n8n Docs. Execute Sub-workflow Trigger node. Official n8n documentation. docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.executeworkflowtrigger/
- n8n Docs. Wait node. Official n8n documentation. docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.wait/
- n8n Docs. Call n8n Workflow Tool node. Official n8n documentation. docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolworkflow/
- n8n Docs. Simple Memory node. Official n8n documentation. docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.memorybufferwindow/
- n8n Docs. Slack Trigger node. Official n8n documentation. docs.n8n.io/integrations/builtin/trigger-nodes/n8n-nodes-base.slacktrigger/
- n8n Docs. Chat Trigger node. Official n8n documentation. docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-langchain.chattrigger/
- n8n Docs. Data Table node. Official n8n documentation. docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.datatable/
- n8n Docs. HTTP Request Tool node. Official n8n documentation. docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolhttprequest/
- OWASP GenAI Security Project (2025). OWASP Top 10 for LLM Applications 2025 (LLM01 Prompt Injection, LLM06 Excessive Agency). genai.owasp.org/llm-top-10/
- OWASP Cheat Sheet Series. SQL Injection Prevention Cheat Sheet. Open Worldwide Application Security Project. cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html
- Brynjolfsson, E., Li, D. & Raymond, L. R. (2025). Generative AI at Work. The Quarterly Journal of Economics, 140(2), 889–942. doi:10.1093/qje/qjae044. doi.org/10.1093/qje/qjae044