· 2 min read
Rules decide, AI writes: how I build n8n + Claude automations
The pattern behind my n8n + Claude automations: code catches what can be checked, Claude judges and drafts, and a person sees every risky item.
- n8n
- Claude
- Automation
Most AI automations I'm asked to fix have the same shape: an email comes in, the whole thing goes to a language model with a long prompt, and whatever the model says happens next.
It demos well. Then it approves an invoice that was already paid, or misses that a ticket came from the biggest customer.
Every automation I build now follows one rule: rules decide what can be checked, AI handles what needs judgment, and a person sees anything risky.
Step 1: let code catch what code can catch
Some questions have exact answers. Is this invoice number already in the log? Does the total match the line items? Is the amount over the approval limit? Is this sender on the VIP list? Has this ticket been open longer than the SLA?
A model can answer these, but not reliably, and you can't explain its answer later. So these run first, as plain code nodes in n8n, before any AI is involved.
For the invoice demo the checks are: duplicate, missing or wrong PO, amount threshold, currency, and line-item math. For support tickets: SLA, VIP and a few keywords that always mean "a person should look at this".
Each check adds a flag to the item. The flags travel with it for the rest of the run.
Step 2: give the model the flags, not the decision
Then Claude gets the item and the flags. Its job is the part code can't do well: read the context, decide between approve, review and hold (or escalate and reply), pick an owner and write the message.
Three settings make this predictable:
- Temperature 0. The same input gives the same decision.
- JSON only. The output must match a schema, so the next node can route on a field instead of parsing prose.
- Flags are hard limits. If code flagged a duplicate, the model can explain it but can't approve it.
Step 3: route by risk
Now the routing is boring, which is what you want:
- Anything flagged or held goes to Slack, to the right person, with the reason.
- Routine items are handled: a clean invoice is approved, a routine ticket gets a drafted reply waiting in Gmail.
- Everything is logged in Google Sheets, so there's a record of what happened and why.
What it looked like on test data
I ran both demos on test data with problems planted on purpose:
- Invoices: 5 of the 6 planted problems were routed to a person, and the 1 clean invoice was approved automatically.
- Tickets: 2 of 5 were escalated (a churn risk and a VIP), and the other 3 got drafted replies.
Those numbers are from demo data, not a client's inbox. But the point holds: the cases that matter go to a person, and everything else stops taking up their morning.
Why this pattern
When something goes wrong in a "send it all to the model" automation, nobody can say why. With this split you can: a rule fired, or it didn't. The model made a judgment call, and its reason is in the log.
It's also cheaper. The model only sees items that need it, with a short prompt, instead of reading everything.
The full build, node by node, is in the invoice and support triage case study.