agentleFS
anatolykoptevanatolykoptev/n8n-mcp-agent/skills/n8n-patterns/SKILL.md

n8n-patterns

Skill0 starsChanged 10 months agoMITView on GitHub

Common n8n workflow patterns. Use when designing workflows to apply proven patterns for error handling, data processing, integrations, and flow control.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Create error workflow with Error Trigger

    line 145
  2. Distinctive:

    Remember: Use proven patterns instead of reinventing.

    line 397

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

n8n Patterns Skill

This skill provides reusable patterns for common n8n workflow scenarios.

Flow Control Patterns

1. Conditional Branching (IF Node)

Trigger → IF (condition) → True Path
                       ↘ → False Path

Use for:

  • Route based on data values
  • Filter valid/invalid items
  • A/B testing logic

2. Multi-Way Branching (Switch Node)

Trigger → Switch (status) → "pending" → Process Pending
                        → "active"  → Process Active
                        → "closed"  → Process Closed
                        → default   → Handle Unknown

Use for:

  • Multiple condition routing
  • Status-based processing
  • Type-based handlers

3. Parallel Processing

Trigger → Branch A ↘
       → Branch B  → Merge → Continue
       → Branch C ↗

Use for:

  • Independent API calls
  • Multi-system updates
  • Parallel data fetching

Data Processing Patterns

4. Batch Processing (Loop Over Items)

{
  "nodes": [
    {
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "parameters": {
        "batchSize": 10
      }
    }
  ]
}

Pattern:

Fetch All → Loop Over Items → Process Batch → Wait → Loop Back
                           ↘ Done → Continue

Use for:

  • API rate limit handling
  • Large dataset processing
  • Memory-efficient operations

5. Data Merging

{
  "nodes": [
    {
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "parameters": {
        "mode": "combine",
        "mergeByFields": {
          "values": [{"field1": "id", "field2": "id"}]
        }
      }
    }
  ]
}

Merge Modes:

ModeDescription
AppendCombine all items
CombineMatch by fields
Choose BranchPick one input
MultiplexCreate all combinations

6. Data Transformation (Code Node)

// Transform array of items
return $input.all().map(item => ({
  json: {
    id: item.json.id,
    fullName: `${item.json.firstName} ${item.json.lastName}`,
    email: item.json.email.toLowerCase(),
    createdAt: new Date().toISOString()
  }
}));

Error Handling Patterns

7. Error Workflow

{
  "nodes": [
    {
      "name": "Error Trigger",
      "type": "n8n-nodes-base.errorTrigger"
    },
    {
      "name": "Slack Notification",
      "type": "n8n-nodes-base.slack",
      "parameters": {
        "channel": "#alerts",
        "text": "Workflow {{$json.workflow.name}} failed: {{$json.execution.url}}"
      }
    }
  ]
}

Setup:

  1. Create error workflow with Error Trigger
  2. In main workflow: Settings → Error Workflow → Select

8. Try/Catch Pattern

Risky Node (Continue on Fail) → IF (has error) → Error Handler
                                             ↘ → Success Path

Code:

// Check for error in previous node
if ($input.first().json.error) {
  // Handle error
  return [{ json: { status: 'failed', reason: $input.first().json.error.message } }];
}
// Continue normally
return $input.all();

9. Retry with Exponential Backoff

Try → On Error → Code (calc delay) → Wait → Retry Counter → IF (< max) → Try
                                                                      ↘ → Fail

Delay Calculation:

const attempt = $input.first().json.attempt || 1;
const baseDelay = 1000; // 1 second
const delay = Math.pow(2, attempt) * baseDelay;
const jitter = delay * 0.2 * Math.random();

return [{
  json: {
    attempt: attempt + 1,
    delayMs: delay + jitter
  }
}];

Integration Patterns

10. Webhook → Process → Respond

Webhook → Validate → Process → Respond to Webhook
                  ↘ Invalid → Error Response

Fast Response Pattern:

Webhook → Respond Immediately (202 Accepted)
       → Continue Processing (async)

11. Schedule → Fetch → Sync

Schedule Trigger → Fetch Source Data
                → Compare with Target
                → Upsert Changes
                → Log Summary

Use for:

  • Database synchronization
  • Data pipelines
  • Regular imports

12. Event → Notify

Webhook (event) → Parse Event → Switch (type)
                             → "order.created" → Slack
                             → "payment.failed" → Email + Slack
                             → "user.signup" → Welcome Email

API Patterns

13. Rate-Limited API Calls

{
  "nodes": [
    {"name": "Loop Over Items", "type": "n8n-nodes-base.splitInBatches", "parameters": {"batchSize": 10}},
    {"name": "API Call", "type": "n8n-nodes-base.httpRequest"},
    {"name": "Wait", "type": "n8n-nodes-base.wait", "parameters": {"unit": "seconds", "amount": 1}}
  ],
  "connections": {
    "Loop Over Items": {"main": [[{"node": "API Call"}]]},
    "API Call": {"main": [[{"node": "Wait"}]]},
    "Wait": {"main": [[{"node": "Loop Over Items"}]]}
  }
}

14. Pagination Pattern

// In Code node for pagination
const allResults = [];
let page = 1;
let hasMore = true;

while (hasMore) {
  const response = await $http.get(`https://api.example.com/items?page=${page}`);
  allResults.push(...response.data.items);
  hasMore = response.data.hasNextPage;
  page++;
}

return allResults.map(item => ({ json: item }));

15. Two-Webhook Polling (Long Operations)

Start Webhook:

Webhook (POST /start) → Generate Job ID → Start Background Process
                      → Respond with Job ID

Poll Webhook:

Webhook (GET /status/:jobId) → Check Status → IF (complete)
                                            → Return Results
                                            ↘ Return "pending"

Sub-Workflow Patterns

16. Modular Sub-Workflows

Parent:

Trigger → Execute Sub-workflow (Validation)
       → Execute Sub-workflow (Processing)
       → Execute Sub-workflow (Notification)

Benefits:

  • Reusable validation logic
  • Easier testing
  • Better organization
  • Sub-executions don't count toward limits

17. Async Sub-Workflow

Trigger → Execute Sub-workflow (Wait: false)
       → Continue immediately
       → Sub-workflow runs in background

Use for:

  • Fire-and-forget operations
  • Background processing
  • Non-blocking notifications

Data Validation Patterns

18. Input Validation Node

// Validation Code node
const item = $input.first().json;
const errors = [];

// Required fields
if (!item.email) errors.push('email is required');
if (!item.name) errors.push('name is required');

// Format validation
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (item.email && !emailRegex.test(item.email)) {
  errors.push('invalid email format');
}

// Range validation
if (item.amount && (item.amount < 0 || item.amount > 10000)) {
  errors.push('amount must be between 0 and 10000');
}

if (errors.length > 0) {
  return [{ json: { valid: false, errors } }];
}

return [{ json: { valid: true, data: item } }];

19. Schema Validation

// JSON Schema validation
const schema = {
  type: 'object',
  required: ['email', 'name'],
  properties: {
    email: { type: 'string', format: 'email' },
    name: { type: 'string', minLength: 1 },
    age: { type: 'integer', minimum: 0, maximum: 150 }
  }
};

// Validate input against schema
// (requires external validator library or custom implementation)

Caching Pattern

20. Static Data Caching

// Use staticData for caching in Code node
const cache = $getWorkflowStaticData('global');

// Check cache
if (cache.data && cache.timestamp > Date.now() - 3600000) {
  return [{ json: cache.data }];
}

// Fetch fresh data
const response = await $http.get('https://api.example.com/data');

// Update cache
cache.data = response.data;
cache.timestamp = Date.now();

return [{ json: response.data }];

Pattern Selection Guide

ScenarioPattern
Process large datasetBatch Processing (#4)
Handle API rate limitsRate-Limited Calls (#13)
Multiple independent callsParallel Processing (#3)
Route by conditionIF/Switch (#1, #2)
Handle errors gracefullyError Workflow (#7)
Retry failed operationsExponential Backoff (#9)
Long-running operationsTwo-Webhook Polling (#15)
Reusable logicSub-Workflows (#16)
Fast webhook responseFast Response (#10)
Data synchronizationSchedule Sync (#11)

Remember: Use proven patterns instead of reinventing. Each pattern has been battle-tested in production workflows.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.