Automate an AI Workflow in n8n: Webhook to LLM to Slack

Wire LLMs into n8n workflows without hand-rolling glue. Covers triggers, model nodes, and where orchestration actually pays off.

Executive Summary: Hand-rolling webhook to LLM to Slack glue is tedious and fragile. This walkthrough builds a runnable n8n pipeline: webhook in, field normalize, LLM triage, optional IF filter, Slack out, and a 202 response. Includes credentials, security, and failure handling. For ops and automation engineers who want a cloneable node list, not a market overview.

This is a runnable n8n walkthrough: webhook in, LLM call, Slack (or email) out. No market overview. You should be able to clone the node list, paste credentials, and see a message land in a channel.

Assumes n8n 1.x (self-hosted or cloud), an OpenAI-compatible API key (or Anthropic), and either Slack or SMTP credentials. Official docs: n8n documentation.

What you will build

Webhook (POST JSON)
  → Set / Edit Fields (normalize payload)
  → Basic LLM Chain or OpenAI node (summarize + action)
  → IF (optional: skip low-priority)
  → Slack node (or Email Send)
  → Respond to Webhook (202 + id)

Example input body:

{
  "source": "support",
  "subject": "Checkout 500 on /pay",
  "body": "Customers see HTTP 500 after card submit since 14:00 IST.",
  "priority": "high"
}

Step 1: Webhook trigger

  1. New workflow → add Webhook.
  2. HTTP Method: POST. Path: ai-triage (or similar).
  3. Respond: Using Respond to Webhook node (so you control status codes).
  4. Save and copy the Test URL / Production URL from the node.

Smoke test:

curl -sS -X POST "$WEBHOOK_URL" \
  -H 'Content-Type: application/json' \
  -d '{"source":"support","subject":"Checkout 500 on /pay","body":"Customers see HTTP 500 after card submit since 14:00 IST.","priority":"high"}'

You should see the execution in n8n with the JSON under the Webhook output.

Step 2: Normalize fields

Add Edit Fields (Set) after the webhook. Map:

  • ticket_subject ← {{$json.body.subject}} (or $json.subject depending on webhook config)
  • ticket_body ← body text
  • priority ← priority or default normal

Keep one flat object. LLMs behave better when the prompt template does not dig through nested webhook envelopes.

Step 3: LLM node

Two common patterns in current n8n:

  • OpenAI / Anthropic chat node: single model call, simplest.
  • Basic LLM Chain (LangChain nodes): prompt template + model + optional output parser.

Prompt template I use for triage:

You are an on-call assistant. Given a support ticket, return STRICT JSON:
{"severity":"low|medium|high|critical","summary":"one sentence","suggested_action":"one sentence","tags":["..."]}

Subject: {{$json.ticket_subject}}
Body: {{$json.ticket_body}}
Priority hint: {{$json.priority}}

Settings that matter:

  • Temperature 0 to 0.2 for classification.
  • Max tokens low (200 to 400); you want JSON, not essays.
  • If the provider supports JSON mode / response format, turn it on.

Add a Code node after the LLM to JSON.parse the content if the model wraps fences. Fail the branch on parse errors instead of posting garbage to Slack.

Step 4: Optional IF filter

Add IF: continue only when severity is high or critical, or when priority hint is high. Low severity can write to a spreadsheet or Data Store for a daily digest.

Step 5: Slack (or email)

Slack node → Operation: send message → Channel: your ops channel.

Message example:

*AI triage* ({{$json.severity}})
{{$json.summary}}
Action: {{$json.suggested_action}}
Tags: {{$json.tags.join(', ')}}

For email, use Send Email with SMTP or your provider node. Same fields in the body.

Step 6: Respond to Webhook

Add Respond to Webhook with status 202 and body:

{ "ok": true, "severity": "{{$json.severity}}", "executionId": "{{$execution.id}}" }

Callers should treat this as accepted-for-processing, not as proof Slack delivered.

Credentials and security checklist

  • Store API keys in n8n Credentials, never in Set node literals.
  • Prefer self-hosted n8n when ticket bodies contain PII; cloud is fine for public demo data.
  • Protect production webhooks: header secret, basic auth, or IP allowlist. Rotate the path if it leaks in a screenshot.
  • Log prompt + raw model output only in non-prod. Production: store severity + summary.
  • Set a timeout and error workflow: if the LLM provider 429s, notify Slack with “triage degraded” instead of silent drop.

Caveats (read before you scale this)

  • Non-determinism: same ticket can flip severity. Keep a human ack for pages that wake people up.
  • Prompt injection: ticket body is untrusted. Do not let the model choose Slack channels, URLs to fetch, or shell commands.
  • Cost: every webhook hits the model. Rate-limit at the webhook or queue with a wait node under burst traffic.
  • Idempotency: retries from the client can double-post. Key off an upstream ticket id in a Data Store before Slack.

Where MCP fits

n8n is great for event pipelines. When the same tools need to be called from an IDE agent or CLI, expose them through Model Context Protocol (MCP) instead of duplicating HTTP glue. For agent loop design and evaluation harnesses, see AI agent harnesses. For reusable instruction packs on Claude, use the Claude Skills series.

Minimal acceptance test

  1. POST the sample JSON; Slack shows a high/critical style message within a few seconds.
  2. POST a “password reset how-to” style body; workflow skips Slack or marks low.
  3. Revoke the LLM key; error path fires and does not return HTTP 200 with a fake success.

When that passes, duplicate the workflow for email digests or CRM updates. Keep the graph boring: one responsibility per node, explicit JSON contracts, and alerts when the model or Slack fails.

Related reading: Model Context Protocol guide, AI agent harnesses, Claude Skills series, LangChain 101, and n8n AI workflow.

Share this article

6 thoughts on “Automate an AI Workflow in n8n: Webhook to LLM to Slack”

  1. Meera

    Measured our approach against the advice before lunch. Results on n8n automation were boring in a good way.

  2. Mohit

    Docked it beside the architecture draft. Wording around n8n automation slipped into the runbook.

  3. Suresh

    Saved under a boring folder name on purpose. First checklist item is n8n automation.

  4. Jordan

    Implementing an automated AI workflow in n8n tonight using your node layout. Hoping the retries behave in prod.

  5. Jordan

    Stuck on how to keep LLM steps visible in ops. n8n as glue for those jobs is the pattern we are adopting.

Leave a Reply

Your email address will not be published. Required fields are marked *