n8n-workflow-best-practices
Skill0 starsChanged 4 months agoMITView on GitHub
Production engineering standard for building, documenting, securing, and version-controlling n8n workflows. Load BEFORE creating, editing, or reviewing any n8n workflow, node, sub-workflow, credential, or workflow JSON export/import. Covers naming, sticky-note documentation, modularity via sub-workflows, error handling, credential security, git-based version control and CI/CD, testing with pinned data, and monitoring.
In this repository7 other files it gives its agents.
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 7 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 9
When this conflicts with an in-repo convention, follow the repo and say so.
- Distinctive: line 21
Update the note in the same change that adds or materially alters a branch, transformation or phase.
- Distinctive: line 22
No ticket or story numbers in notes.
- Very specific: line 33
Every production workflow sets Settings → Error Workflow.
- Distinctive: line 46
Prefer an OAuth2 credential over a static API key where the service offers both.
- Distinctive: line 54
When editing exported JSON programmatically, keep the serialization n8n produced (do not reformat).
- Very specific: line 67
Run the export and jq checks before committing an export and in CI.
- Distinctive: line 78
If a needed credential does not exist, ask the user to create it.
- Distinctive: line 80
If a commit hook conflicts with the required sync direction, say so and ask.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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.
Files
n8n Workflow Best Practices
Applies to n8n workflows, sub-workflows, credentials and their JSON exports in git, self-hosted or cloud. When this conflicts with an in-repo convention, follow the repo and say so.
1. Naming
- Rename every default-named node (
HTTP Request 1,IF 2,Set 3); a change is not complete while one remains. - Nodes: verb-first, naming the action, not the node type:
Fetch Stripe Invoice,Check: User Has Email,Send Slack Alert: Sync Failed. - Workflows:
[Area] – Description – vN, e.g.[Sales] – Lead Sync HubSpot → CRM – v2.
2. Sticky Notes
- A sticky note on every non-obvious branch or transformation, so a complex
IF/Switch/Mergeis understood without opening the node. - One note per logical phase (e.g. Validate Input → Enrich → Write to CRM → Notify), stating the phase's objective and, ideally, its start and end nodes.
- Update the note in the same change that adds or materially alters a branch, transformation or phase.
- No ticket or story numbers in notes.
3. Sub-workflows
- One workflow, one job; keep each at or under 15–20 nodes and decompose past that.
- Extract a sub-workflow when a second caller appears; call or extend an existing one instead of copying node groups.
- Define an explicit, minimal input/output contract on the
Execute Sub-workflow Triggernode. - Shared sub-workflows are broadly viewable but narrowly editable: restrict write access.
4. Error Handling
- Every production workflow sets Settings → Error Workflow. The Error Workflow starts with an
Error Triggernode, need not be active, and one can serve many workflows. - Its alert carries the workflow name, failed node, error message and a link to the failed execution.
- It also records each failure in one central store (a Postgres table, a sheet, or the observability stack).
- The Error Workflow never fires for a workflow that stops running without an error (deactivated by hand, or its trigger stops receiving events); for scheduled production workflows, also check Executions for missing expected runs.
Retry On Failon nodes exposed to transient faults (timeouts, rate limits, flaky upstreams):Max. Tries2-5 with a fixedWait Between Tries(at most 5000 ms; n8n has no backoff); after the cap, escalate, never loop. It retries every error, 4xx included, so leave it off where a 4xx must not repeat (a paid or side-effecting call) and branch on the error instead.On Error→Continue(the legacyContinue On Fail) only where the failure is acceptable, such as an optional enrichment step.- Map failure classes to actions: retry
5xxand timeouts; refresh the credential or alert on401; route422to a human review queue. Branch on the error withOn Error→Continue (using error output). A continued error usually does not fail the execution, so the Error Workflow does not see it: end every error branch that is not a recovery in aStop and Errornode.
5. Credentials and Execution Data
- Secrets live only in n8n's credential store, never in a node parameter, a
Setnode, a sticky note or a$envexpression; an export then references each credential only ascredentials.<type>: {id, name}on the node. - Self-hosted: set a persistent
N8N_ENCRYPTION_KEY; the key auto-generated on first launch (in~/.n8n) is unfit for production. Losing or rotating it silently invalidates every stored credential. - Give each environment's credentials identical names, so a promoted workflow resolves to that environment's credentials without an edit.
- Prefer an OAuth2 credential over a static API key where the service offers both.
- Set an execution-data retention policy (
EXECUTIONS_DATA_PRUNE=true,EXECUTIONS_DATA_MAX_AGEin hours) and redact PII and full request/response payloads from the central failure log and error alerts.
6. Version Control and Environments
- The instance database is the source of truth for what runs; the committed JSON export is the git artifact.
- Know the sync direction before touching either side: last change in the n8n UI → export DB → file; last change in the file, or a UI "Download" (which captures unsaved canvas state, not the DB) → import file → DB. Check for uncommitted diffs before exporting; the wrong direction silently overwrites the newer side.
- One workflow per file.
- When editing exported JSON programmatically, keep the serialization n8n produced (do not reformat).
- Each environment is its own n8n instance, or at minimum its own credential and variable set. Promote via export/import or the API, one environment at a time (dev → staging → prod); never edit production directly, including to make it match git.
7. Testing
- Pin a node's output after a real run and re-execute downstream nodes against it.
- Edit pinned data to reach hard-to-trigger branches: turn a success into a failure shape, empty an array, null a field.
- Pins apply only to manual editor runs, never to production executions; clear stale pins before trusting a manual run.
- Exercise failure paths (malformed input, expired credential, upstream timeout) and confirm the Error Workflow fires and alerts. The
Error Triggerfires only when an automatic execution fails, never for a manual run, so test it through the real trigger. - A webhook's test and production URLs are different endpoints; verify against the production URL, whose runs appear under Executions rather than on the canvas, before calling a webhook workflow done.
8. Gates
Run the export and jq checks before committing an export and in CI; run import only to promote. Confirm flags with n8n <command> --help on the installed version.
n8n export:workflow --all --separate --output=workflows/ # DB -> files, one <id>.json per workflow
n8n import:workflow --separate --input=workflows/ # files -> DB; deactivates every imported workflow (--activeState=fromJson keeps each file's state: queue/multi-main mode only)
jq empty workflows/*.json
jq -r 'select(.settings.errorWorkflow == null) | .name' workflows/*.json9. Agent Rules
- If a needed credential does not exist, ask the user to create it; never insert a realistic-looking placeholder.
- State in the summary which sync direction you used and why, and flag any production workflow with no Error Workflow set.
- If a commit hook conflicts with the required sync direction, say so and ask.
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
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.

