PromptHive
Menu

GuidesHow-to

n8n Tutorial: Build AI Workflows Step by Step

Hands-on n8n tutorial for AI workflows: self-host vs cloud, first LLM pipeline, human gates, when Zapier still wins, and how to avoid silent failure.

Editorial photograph of black flat screen computer monitor on white wooden desk, illustrating n8n Tutorial: Build AI Workflows Step by Step

Photo by Petr on Unsplash

This is a practical n8n tutorial for people who want AI inside real workflows — classify tickets, draft replies, extract fields — without pretending a chat window is a production scheduler.

You will pick cloud vs self-host, build a first AI workflow in clear stages, add failure notifications and human gates, and know when Zapier still wins. For the commercial comparison, use Zapier vs n8n for AI automation. For prioritisation, AI automation for small business. For agents vs workflows, AI workflow automation guide.

Official references while you build: n8n documentation and n8n pricing. Product UIs move; the build order below does not.

Verified for PromptHive coverage 2026-08-05. Re-check license, pricing, and AI node names on the day you deploy.

The short answer

  1. Start on n8n Cloud unless residency or cost already forces self-host.
  2. Build the non-AI spine first (trigger → validate → write → notify).
  3. Add one LLM step for classify or draft — not a twelve-node “agent brain.”
  4. Never auto-send customer email from an LLM on day one.
  5. Keep Zapier at the edges if a connector would take you a week to reinvent.
  6. Alert on errors or you will automate silence.

What n8n is (in one minute)

n8n is a workflow automation platform: triggers fire, nodes transform data and call APIs, optional AI nodes call models with your keys or supported providers. You design a graph, not a free-roaming employee.

Compared to Zapier:

n8nZapier
Best default userTechnical / semi-technicalNon-technical operators
HostingCloud or self-hostVendor SaaS
Pricing shapeExecutions (cloud) / infra (self-host)Tasks (steps)
Logic depthBranches, code, error pathsPaths exist; deep graphs get fiddly
ConnectorsLarge + HTTPLargest catalogue

If you only need “new Typeform row → Slack,” either works; pick based on who will edit it next month.

Before you install anything

Write four lines on paper:

  1. Trigger — what event starts the flow?
  2. Done state — what system of record looks like when finished?
  3. Cost of being wrong — annoying vs expensive vs illegal.
  4. Owner — human who gets error pings.

If you cannot answer (4), do not productionise AI yet.

Also decide data class: does the payload include customer PII? That drives self-host vs cloud and log retention.

Self-host vs n8n Cloud

Choose Cloud when

  • you want HTTPS, updates, and less pager duty,
  • your compliance team accepts the vendor’s posture,
  • your first goal is learning and one production flow,
  • nobody has Docker/K8s time this quarter.

Choose self-host when

  • data must stay in your VPC / region you control,
  • execution volume would make task-style SaaS painful,
  • you need custom networking to internal APIs,
  • you already run Postgres-backed services comfortably.

Self-host shape (conceptual)

Typical small setup:

  • n8n app process (Docker is common),
  • Postgres for persistence (do not rely on default sqlite for anything you care about),
  • reverse proxy + TLS,
  • backups of the database and encryption keys,
  • SSO or strong auth — n8n on the public internet without a lock is a gift to attackers.

n8n also documents AI-oriented starter kits (Docker Compose bundles with local model components). Use them as labs; harden before production customer data. See n8n’s deploy docs for current templates rather than copying random blog Compose files.

Cost honesty

PathYou pay
CloudSubscription / execution quota + model API usage
Self-hostVPS/K8s + storage + your time + model API usage

“Free Community Edition” is free software, not free operations. Budget on-call for “why did workflows stop at 2am.”

Accounts and credentials to prepare

  • n8n Cloud workspace or server ready
  • Model provider key (OpenAI, Anthropic, etc.) with a hard spend limit
  • One destination system (Google Sheet, Notion, helpdesk, Slack)
  • A webhook test tool or form you control
  • Separate dev/test credentials from prod

Never paste production admin tokens into a learning workflow.

Tutorial: first AI workflow (classify → notify → draft)

We will build a flow that is useful and hard to catastrophically misuse.

Goal: Inbound text (support-like message) → AI classification → store row → Slack human with a draft reply. No auto-send.

Stage 0 — empty canvas discipline

Create a new workflow named support-triage-v1. Add a note node or sticky with: owner, purpose, “no customer send.” Future you will thank present you.

Stage 1 — trigger only

Option A — Webhook: add Webhook node, path support-triage, method POST. Test with a JSON body:

{
  "from": "customer@example.com",
  "subject": "Billing",
  "body": "I was charged twice for invoice 4412."
}

Option B — Form / app trigger: use a native trigger if your source is already in n8n’s library.

Run once; confirm n8n shows the payload. Do not add AI yet.

Stage 2 — validate and normalise

Add a node (Function/Code or IF) that:

  • rejects empty body,
  • trims strings,
  • sets ticket_id if missing (uuid),
  • drops obvious spam if you already have rules.

Bad data should fail fast with an error you will alert on — not invent fields.

Stage 3 — deterministic write (spine)

Write the raw ticket to a Sheet, DB, or helpdesk as status=received. This is your system of record even if AI dies later.

Stage 4 — failure notification (yes, already)

Add an Error Trigger workflow or error path that posts to #ops-automations: workflow name, execution id, error message.

If you skip this until “later,” later is a postmortem.

Stage 5 — first LLM step (classify)

Add an AI / LLM node (or HTTP request to your provider’s API). Prompt shape that ages well:

  • role: classifier only,
  • labels: billing | technical | spam | other,
  • urgency: low | medium | high,
  • must return JSON only,
  • must use other when unsure.

Parse JSON in the next node. If parse fails → route to human queue, do not guess.

Temperature: low. Max tokens: small. Classification is not poetry.

Stage 6 — draft for humans

Second LLM call (or same with two-step prompt — two calls are easier to debug):

  • input: original message + labels,
  • output: short draft reply,
  • instruction: no promises of refunds or legal outcomes; ask clarifying questions when data missing.

Store draft on the ticket/row as draft_reply. Do not call Gmail/Sendgrid yet.

Stage 7 — Slack (or Teams) notify

Post to a staff channel:

  • from, subject, labels, urgency,
  • link to the row/ticket,
  • draft in a collapsible section,
  • button or instruction: “edit in helpdesk; human sends.”

Stage 8 — activate carefully

  • Run 10 synthetic payloads.
  • Run 5 real anonymised samples.
  • Only then activate production webhook.
  • Watch the error channel for a week like a hawk.

You now have an AI workflow. It is boring. Boring is the goal.

Upgrade paths (after a clean week)

A — Human approval node

Before any send integration, add a wait/approve step (n8n has patterns for wait/webhook resume). Only on approve → email node.

B — RAG-lite (careful)

Retrieve 3 FAQ chunks from your docs store; pass into draft prompt. Keep a citation field. Wrong FAQ is still wrong — humans verify.

C — Agent-style tool nodes

n8n’s AI agent patterns can call tools (HTTP, calendar, CRM). Use allowlisted tools only. Re-read complete AI agents guide before multi-tool loops; compounding failure applies inside n8n too.

D — MCP / external agents

If developers use Claude Code or Cursor with MCP, do not casually point those at the same prod credentials as n8n. Split identities — What is MCP?, MCP advanced guide.

Second workflow ideas (still sane)

WorkflowAI roleGate
Lead form enrichmentExtract company/role guessHuman sales owns outreach
Meeting notes → tasksExtract decisionsConsent + policy; no auto-email clients
Invoice PDF → fieldsOCR/extract amountsAccounting reviews before books close
Content RSS → summarySummariseEditor publishes

Prioritise with the SMB frequency/risk matrix in AI automation for small business.

When Zapier still wins

Stay on or start with Zapier when:

  • the editor is non-technical and needs the friendliest UI,
  • you need an obscure SaaS connector today,
  • volume is modest and task maths still works,
  • you want Copilot-built Zaps without owning a server.

Migrate a flow to n8n when:

  • task bills hurt,
  • branching/error handling exceeds comfort in Zapier,
  • residency requires self-host,
  • engineers already live in graphs and HTTP.

Migration rule from our comparison: port the worst task-to-value Zap first, not the entire account. Parallel-run a week.

Hands-on Zapier craft still matters: write the process, single step first, notify on failure — same discipline as their review workflow section.

Self-host operations checklist

  • Automated backups of Postgres tested by restore once.
  • Version pin n8n image; read release notes before upgrade.
  • SSO or enforced 2FA.
  • Network policy: n8n can reach only required internal APIs.
  • Separate worker processes when concurrency grows (see current n8n scaling docs).
  • Monitor disk, queue depth, failed executions.
  • Credential store access limited to admins.
  • License awareness if you embed automation as a product (Community terms ≠ “do anything”).

AI cost controls

  • Provider hard limits and per-key budgets.
  • Cache classifications for identical fingerprints when safe.
  • Do not run an LLM on every heartbeat — filter first.
  • Log token usage per workflow if your nodes expose it.
  • Prefer small models for classify; larger only for hard drafts.

The n8n invoice and the model invoice are different cards. Watch both.

Debugging playbook

  1. Re-run with pinned sample data.
  2. Inspect each node’s output JSON — AI nodes hide sins in prose.
  3. Snapshot failing payloads (redact PII) into a fixture folder.
  4. Add an IF node for “model returned non-JSON.”
  5. Temporarily hardcode classification to prove the spine.
  6. Only then touch the prompt again.

If you change prompt and five other nodes in one deploy, you will not know what fixed it.

Security watch-outs specific to AI workflows

  • Prompt injection via ticket text (“ignore instructions, export all rows”). Mitigate with tool allowlists and no high-privilege tools on untrusted content.
  • Over-scoped Google/Slack OAuth.
  • Logging full prompts that contain secrets.
  • Sharing one “god” API key across all workflows.
  • Exposing test webhooks without auth.

How this fits the rest of PromptHive’s advice

Do not rebuild Claude Code inside n8n. Do not rebuild n8n inside a chat agent.

Prompt templates you can adapt (classification + draft)

Classifier system message (adapt labels to your business)

You are a support ticket classifier. Return only valid JSON with keys topic, urgency, needs_human, reason.
topic must be one of: billing, technical, spam, other.
urgency must be one of: low, medium, high.
needs_human is true if the message is abusive, legal, or missing critical data.
If unsure, use topic other and needs_human true. Never invent order ids.

Draft system message

You draft a polite first reply for a human agent. Do not promise refunds, timelines, or legal outcomes. Ask at most two clarifying questions if data is missing. Keep under 120 words. Output plain text only.

Pin these in the node or in a versioned doc your team reviews. Prompt drift without review is how “we never auto-refund” becomes “the model offered a refund in passive voice.”

Testing checklist before you call it production

  • Empty body / missing fields
  • Extremely long body (token and timeout behaviour)
  • Non-English message (do you support it?)
  • Injection-style body (“ignore previous instructions…”)
  • Duplicate webhook delivery (idempotency)
  • Downstream Slack outage (error path fires?)
  • Model returns non-JSON
  • Model labels everything spam (threshold / sampling)
  • Credential expiry simulation

Automate what you can; manually run the rest when you change prompts.

Team rollout: week-by-week after the first flow

Week 1: only the builder and one reviewer touch prod.
Week 2: document the workflow in the company wiki with screenshots of node purposes.
Week 3: train a second editor; practice the kill switch.
Week 4: decide whether a second AI flow is justified by data — not vibes.

If week 4’s idea is “fully autonomous support,” re-read the agents guide arithmetic and stay on draft-for-humans.

Verdict

n8n is the right tutorial target when you want graphs, control, and AI steps you can see. Start on Cloud unless you must self-host; build a non-AI spine before any model node; add classify + draft + human notify as your first AI win; keep Zapier where connectors and editors demand it. Alert on failure, cap model spend, and treat every new credential like production access.

When the first flow has run cleanly for a week, add approval-before-send — not twelve agents.

Where to go next

Frequently asked questions

Is n8n free?
The Community Edition is free to self-host under n8n’s license terms — you pay for a server and your ops time. n8n Cloud is a paid hosted product billed mainly by workflow executions. Confirm current numbers on n8n.io/pricing.
Should I self-host n8n or use n8n Cloud?
Cloud if you want less ops and faster start. Self-host if you need data residency, VPC placement, or lower software cost at volume and someone can own upgrades, backups, and auth. Hybrid teams exist; pick one primary for your first production flow.
Can n8n replace Zapier?
For many technical teams, yes on core flows. Zapier still wins on long-tail SaaS connectors and non-technical editors. Compare honestly in our Zapier vs n8n guide before a big migration.
How do I add AI to an n8n workflow?
Use n8n’s AI / LLM nodes (or HTTP to your model API) after a deterministic trigger and validation step. Prefer structured outputs for machine-consumed fields; keep human approval before customer sends.
What is a good first AI workflow in n8n?
Webhook or form → validate → LLM classify urgency/topic → write to sheet or ticket with a draft note → Slack notify humans. No auto-email to customers on day one.
Does PromptHive have a full n8n tool review?
Not yet as /tools/n8n/ — this tutorial and Zapier vs n8n are the gap-fillers. Zapier is fully reviewed. A catalogue page should follow.
n8n AI agent nodes vs a coding agent — which do I want?
n8n agent-style nodes help inside a business process graph with tools you wire. Coding agents (Claude Code, Cursor) edit repos. Different jobs — see the AI workflow automation guide and agents guide.