n8n Basics for AI Workflows
Low-code automation: connect APIs, LLMs, Slack, and databases without writing a full app.
Interview tip Great for ops automations: "new email → summarize with LLM → post to Slack." Not for core product logic at scale.
① What you must know (30 sec)
n8n is a visual workflow automation tool where nodes are triggers (webhook, schedule, email) and actions (HTTP, OpenAI, Google Sheets, Slack). Data flows as JSON between nodes — ideal for ops automations, internal tools, and AI-assisted glue code without deploying a full backend.
Analogy: n8n is Zapier with a wiring diagram and self-host option — connect boxes instead of writing integration boilerplate.
② How it works
Typical AI workflow
Trigger→Fetch data→Transform JSON→LLM node→Slack / DB / Email
Each node receives items from the previous node. Use Set and Code nodes to shape fields before the LLM prompt.
Self-host n8n for data privacy; n8n Cloud for fastest start. Credentials are encrypted per workflow.
③ Step-by-step (hands-on)
Step 1 — Install or sign up
n8n Cloud for POC; Docker self-host for internal data: docker run n8nio/n8n. Create admin account.
Step 2 — Add credentials
Store OpenAI, Slack, and Gmail credentials in n8n Credentials — never paste keys in node fields.
Step 3 — Build trigger → action
Start with Schedule Trigger (daily 9am) or Webhook. Add one action node; execute to verify data shape.
Step 4 — Insert LLM node
OpenAI node: map {{ $json.body }} into prompt template. Set model, max tokens, and system message.
Step 5 — Branch and error handling
Use IF node for conditions; Error Trigger workflow for failures; Send alert to Slack on error.
Step 6 — Add human approval
Slack node with "wait for approval" or manual trigger before send — critical for customer-facing messages.
④ Code / config patterns
| Pattern | Nodes | Use case |
|---|---|---|
| Scheduled digest | Cron → HTTP → LLM → Slack | Daily reports |
| Event-driven | Webhook → LLM classify → DB | Ticket triage |
| RAG-lite | Google Drive → extract text → LLM → Notion | Doc summarization |
| Human gate | LLM draft → Wait → Send email | Outbound comms |
// Code node (JavaScript) — shape data before LLM
const items = $input.all();
return items.map(item => ({
json: {
prompt: `Summarize in 3 bullets:\n${item.json.text}`,
source_id: item.json.id
}
}));⑤ Production & pitfalls
| Pitfall | Why it hurts | Fix |
|---|---|---|
| Core product on n8n | Hard to test, version, scale | Migrate critical paths to code; keep ops on n8n |
| No error workflow | Silent failures overnight | Error Trigger + Slack alert on every workflow |
| Huge payloads to LLM | Cost spikes, context overflow | Truncate/summarize in Code node first |
| Credentials in exported JSON | Leaked keys in git | Use credential refs; scrub exports |
| No idempotency | Duplicate Slack posts on retry | Track processed IDs in DB node |
| Unreviewed LLM output sent | Embarrassing or wrong messages | Human approval node before send |
Production tips:
- Export workflows to git for version control
- Separate dev and prod n8n instances
- Rate limit webhook triggers at reverse proxy
- Monitor execution history and failure rate weekly
⑥ Interview / on-the-job Q&A
| Question | Answer |
|---|---|
| What is n8n? | Open-source workflow automation with visual node editor and 400+ integrations. |
| How does data flow? | JSON items pass node to node; access fields with {{ $json.field }} expressions. |
| n8n vs Zapier? | n8n is self-hostable, more flexible Code nodes, better for technical teams. |
| When use LLM node? | Classification, summarization, extraction — not real-time chat at scale. |
| Self-host vs cloud? | Self-host for PII/compliance; cloud for speed and zero ops. |
| When migrate to code? | Need unit tests, CI/CD, high QPS, or complex business logic. |
⑦ Tools & ecosystem
- LLM nodes: OpenAI, Anthropic (HTTP), Ollama (local)
- Triggers: Webhook, Schedule, Gmail, GitHub
- Actions: Slack, Notion, Airtable, Postgres
- Hosting: n8n Cloud, Docker, Kubernetes
⑧ Revision checklist
- Credentials stored in n8n vault, not inline
- Workflow exported to git
- Error Trigger workflow sends alerts
- LLM prompts tested with 5 sample inputs
- Human approval before external sends
- Payload size limited before LLM node
- Schedule timezone documented
- Dev/prod instances separated
- Execution failure rate monitored