This page covers the critical item flow mental model. See also: n8n Overview, AI Agents, Self-Hosting.

Item Flow — The Critical Mental Model

The number of items entering a node determines how many times it executes. 3 items in = the next node runs 3 times. This is the single most important concept in n8n.

Split Out / Aggregate / Loop

1 item with [A, B, C]  ──>  Split Out  ──>  3 separate items (A, B, C)
3 separate items        ──>  Aggregate  ──>  1 item with [A, B, C]
100 items               ──>  Loop (batch=10) ──>  10 batches of 10 items
NodeTransformsUse When
Split Out1 item with array -> N itemsProcess each array element independently
AggregateN items -> 1 item with arrayCombine results into a single payload
LoopN items -> batches of MRate limits, memory issues, sequential processing
Forgetting that item count multiplies execution is the most common mistake. An AI Agent node processing 50 items = 50 separate LLM calls. Use Loop with batch size 1-5 for expensive operations.

Sub-Workflows

Reusable, modular workflow components called from parent workflows.

Structure

Parent Workflow:
  Trigger → Process → Execute Sub Workflow → Continue

Sub-Workflow:
  Execute Sub Workflow Trigger → [logic] → Final Node (output returned to parent)

Rules

1

Must start with Execute Sub Workflow trigger

The sub-workflow needs this specific trigger node to receive data from the parent.
2

Define input parameters manually

Use “Define using fields below” — not “auto-detect”. Explicit is reliable.
3

Must be published

Changes to sub-workflows don’t take effect in the parent until published.
4

Returns final node output

The output of the last node in the sub-workflow is returned to the parent.

When to Create Sub-Workflows

  • Same logic used across multiple workflows
  • Complex node chains that clutter the main workflow
  • Components that need independent testing
When using an AI Agent inside a sub-workflow, set the user message source to “Define below” and map the incoming variable explicitly. Without this, the agent receives no prompt and errors silently.

Error Handling Patterns

PatternHowUse When
Error Trigger workflowSeparate workflow on any failureGlobal monitoring and alerting
Continue on ErrorNode setting — proceed despite failureGraceful degradation
Try/Catch with IfCheck output, route errors to recoveryPer-node error handling
Retry with LoopWrap failing node in Loop with counterTransient API failures
Human in the LoopPause node waits for approvalCritical decisions

Human in the Loop (HITL)

The Pause node stops workflow execution and waits for a human to approve or reject before continuing. Use for:

  • Sending emails/messages on behalf of the user
  • Financial transactions
  • Calendar scheduling
  • Any action that’s hard to undo

Webhooks

Webhook Trigger

External service → POST https://your-n8n.com/webhook/abc123
                → Workflow processes data
                → Returns JSON response

Security Best Practices

  • Validate incoming request headers (API keys, signatures)
  • Check source IP if possible
  • Authenticate before processing any data
  • Never expose sensitive data in webhook URLs

Production Best Practices

Development Rules
  1. Build node-by-node. Test after each addition, not at the end.
  2. Pin test data (shortcut: P) after successful API/AI calls. Saves credits.
  3. Use absolute node references ($('NodeName')) — they survive restructuring.
  4. Rename nodes descriptively. “Process Email” not “HTTP Request 3”.
  5. Test with cheap models first (GPT-4o Mini, Gemini Flash), switch to production models last.
Architecture Rules
  1. Sub-workflows for reuse. Copy-paste the same nodes twice? Extract a sub-workflow.
  2. Separation of concerns. System message = static rules. User message = dynamic input. Tools = actions.
  3. Explicit over implicit. Define all fields manually. Never rely on auto-detection in production.
  4. Credentials in n8n. Never hardcode API keys in Code nodes or expressions.
  5. Version control. Export workflows as JSON. Track changes in Git.
Reliability Rules
  1. Error workflows for monitoring. Dedicated error-handling workflow that sends alerts.
  2. Rate limit protection. Loop nodes with small batch sizes for API-heavy workflows.
  3. Log agent actions. Track tool calls, token usage, and outcomes.
  4. Human in the loop for irreversible actions. Pause before sending, deleting, paying.
  5. Test edge cases. Empty inputs, missing fields, API timeouts, malformed data.