AI Automation

Automation first, AI second: use LLMs only where judgment is needed

TL;DR

Steps with clear rules (filtering, format conversion, API calls, math) → plain logic: cheap, fast, stable, testable. Steps needing language understanding, fuzzy classification, summarizing, drafting → an LLM. Result: lower cost and fewer unpredictable failures.

With an LLM at hand it’s tempting to “let AI do everything”: AI reads email, AI filters spam, AI calculates refunds, AI decides who gets what. The result is usually an expensive, slow system that occasionally fails in unpredictable ways. The opposite principle works far better: automate with ordinary logic first, and use the LLM only for steps that genuinely need judgement.

Two kinds of steps in every process

Deterministic steps (clear rules)Judgement steps
ExamplesFilter by sender, reformat dates, call an API, calculate, match IDsUnderstand intent in an email, fuzzy classification, summarise, draft a reply
Toolif/else, regex, SQL, code, built-in n8n nodesLLM
CostPractically zeroTokens on every run
SpeedMillisecondsSeconds
Reliability100% repeatable and testableProbabilistic; needs evals

Example: handling refund-request emails

StepUseWhy
Skip auto-replies, newsletters, spamRulesHeaders and sender are enough; no tokens spent
Read the content and work out what the customer wantsLLMNatural language, many ways of saying it
Extract the order IDRegex first, LLM as fallbackIDs have a fixed format; only ask the LLM when regex fails
Look up the order in the databaseCode / APIStructured data
Calculate the refund, check the return windowCodeMoney can’t be “approximately right”
Draft a polite replyLLMNeeds context-appropriate wording
Approve refunds above a thresholdHumanFinancial risk

Of seven steps, only two or three need an LLM. The rest are cheaper, faster and testable with ordinary unit tests.

Why this works better

  • Cost: every step moved from LLM to code removes one model call per record.
  • Reliability: LLM failures are hard to predict; code failures come with stack traces and can be reproduced.
  • Debuggability: when output is wrong, you know which step to look at.
  • Swappability: a small, well-defined LLM part means changing models or prompts doesn’t ripple through everything.

It’s also the spirit of Anthropic’s “Building effective agents”: find the simplest solution possible and add complexity only when you can measure that it improves results. Many problems need nothing more than one well-designed LLM call with retrieval and examples — no agent required.

Four questions for every step

  1. Can I write if/else, a regex or SQL for it? Yes → don’t use AI.
  2. How costly is one mistake? High (money, legal, key customers) → human approval; AI only proposes.
  3. Does the output need a fixed structure? Yes → enforce a JSON schema (structured outputs) and validate.
  4. Do I have sample data to evaluate it? Not yet → prepare 50–100 hand-labelled examples before going live.

The “sandwich” architecture

[Code: filter and normalise input]
        ↓
[LLM: understand / classify / draft]  → JSON per schema
        ↓
[Code: validate, look up, calculate, route]
        ↓
[Human: approve when risk is high / confidence is low]

The LLM is “sandwiched” between two layers of code: the first trims and cleans the input, the second checks and executes. LLM output never flows straight into an action with consequences.

How to apply it

  • Developers: Review existing workflows: which LLM steps could be rules? Start with input filtering — it usually saves the most tokens.
  • Tech Leads: In design reviews, ask for workflow diagrams that clearly colour the “deterministic part” and the “AI part”.
  • PMs: When estimating automation projects, split the two. The AI part needs extra time for evaluation data, prompt tuning and edge cases — don’t estimate it like ordinary code.

Sources & references

  1. Building effective agents — Anthropic (Erik Schluntz, Barry Zhang)
  2. Structured outputs — Claude Docs