DEV Community

Cover image for I keep seeing people build an AI lead processing agent when they really need a 6-step rules engine
Lars Winstand
Lars Winstand

Posted on • Originally published at standardcompute.com

I keep seeing people build an AI lead processing agent when they really need a 6-step rules engine

I knew this was worth writing when I saw a Reddit thread describing an “AI lead processing agent” for underwriting.

The job sounded fancy until you translated it into actual steps:

  1. Watch an inbox
  2. Extract business name + monthly deposits
  3. Check Salesforce, HubSpot, or a custom CRM/CMR
  4. See whether the lead already exists
  5. Route to new banks if needed
  6. Assign a rep only if deposits are over $30,000

That is not an agent problem.

That is workflow logic with one messy-input step.

And a commenter in r/openclaw said the quiet part out loud:

Don't use AI for deterministic processing. You can write a simple script for this and it will be much more reliable and cheaper.

I think that’s exactly right.

The mistake: using an LLM as a decision engine

A lot of teams are building “AI lead gen automation” that should really be split into two pieces:

  • fuzzy extraction
  • deterministic state transitions

Those are not the same thing.

If the input is ugly — forwarded email chains, scanned PDFs, weird broker notes, inconsistent merchant statements — then yes, use Claude, GPT-5, or Qwen to extract fields.

But once you have the fields, stop asking the model to make business decisions that can be expressed as code.

Bad pattern:

  • “Figure out whether this is a duplicate”
  • “Decide whether to assign a rep”
  • “Determine which bank should receive this”

Better pattern:

  • model extracts business_name, monthly_deposits, contact_email
  • code checks CRM state
  • code applies explicit rules
  • code writes the result atomically

That split matters a lot in production.

The architecture I’d actually ship

If I were building underwriting intake or lead routing, I’d use this shape:

  1. Trigger on inbound email/webhook
  2. Parse sender/subject/attachments deterministically
  3. Send only messy text to an LLM for strict extraction
  4. Normalize extracted values
  5. Check CRM using normalized identifiers
  6. In one locked step, decide duplicate/new/assignment
  7. Only after the write succeeds, trigger downstream actions

That gives you a small LLM boundary and a deterministic core.

Put the LLM in a tiny box

The safest contract is something boring like this:

{
  "business_name": "Blue Lantern LLC",
  "monthly_deposits": 35000,
  "contact_email": "ops@bluelantern.com",
  "requested_amount": 50000,
  "confidence": 0.91
}
Enter fullscreen mode Exit fullscreen mode

That’s a good use of GPT-5, Claude Sonnet, or Qwen.

What I would not do is this:

Read the email, decide if the lead is a duplicate, determine whether it qualifies for rep assignment, and choose which bank should receive it.
Enter fullscreen mode Exit fullscreen mode

That prompt looks convenient right up until you need consistency, auditability, and duplicate prevention.

What actually breaks first in production

Not the prompt.

Concurrency.

This is where agent demos usually lie to you. They work great with one email.

Then two brokers forward the same merchant 20 seconds apart.

Now both workers do this:

  • query CRM
  • see no assigned record yet
  • decide the lead is new
  • route it
  • create duplicate work

That’s not an AI failure. That’s a race condition.

And no amount of “reasoning” fixes a missing transaction boundary.

The rule that matters more than your prompt

If your flow includes duplicate checks, threshold-based assignment, or bank routing, the critical part is the write path.

This logic should be explicit:

def process_lead(crm_record_exists, new_banks_available, monthly_deposits):
    if crm_record_exists:
        if new_banks_available:
            return "route_to_new_banks"
        return "mark_duplicate_internal"

    if monthly_deposits >= 30000:
        return "assign_rep_and_send_docs"

    return "mark_low_revenue"
Enter fullscreen mode Exit fullscreen mode

And the final decision should happen inside one transaction or locked operation.

For example, in PostgreSQL:

BEGIN;

SELECT id
FROM leads
WHERE normalized_business_name = $1
FOR UPDATE;

-- if exists, update state
-- if not, insert new row with unique constraint protection

COMMIT;
Enter fullscreen mode Exit fullscreen mode

Or with an upsert:

INSERT INTO leads (normalized_business_name, contact_email, monthly_deposits, status)
VALUES ($1, $2, $3, $4)
ON CONFLICT (normalized_business_name)
DO UPDATE SET updated_at = NOW()
RETURNING id, status;
Enter fullscreen mode Exit fullscreen mode

That is the part worth obsessing over.

Not whether your agent sounds confident while making inconsistent choices.

A practical hybrid design

This is the version I’d recommend to most teams using n8n, Make, Zapier, OpenClaw, or custom Python/TypeScript workers.

Layer What it should do
Trigger/orchestration Watch inboxes, webhooks, retries, notifications
LLM step Extract fields from messy email/PDF text
Normalization step Clean business names, parse currency, standardize email/domain
Rules engine Apply deposit thresholds, duplicate policy, assignment logic
Transaction-safe write Insert/update CRM state atomically
Downstream actions Send docs, notify reps, route to banks

This is what “AI where it helps, code where it matters” actually looks like.

Example: n8n + Python worker

If I wanted to move fast, I’d use n8n for orchestration and a small Python service for the transaction-sensitive part.

n8n flow

  • IMAP Email Trigger or webhook
  • extract attachments/text
  • LLM node for structured extraction
  • HTTP request to internal worker
  • Slack/email notification after successful write

Python worker sketch

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

class LeadPayload(BaseModel):
    business_name: str
    monthly_deposits: float
    contact_email: str
    requested_amount: float | None = None

@app.post("/process-lead")
def process_lead(payload: LeadPayload):
    normalized_name = payload.business_name.strip().lower()

    # pseudo-code for transaction-safe logic
    # begin transaction
    # lock matching lead row or rely on unique constraint
    # check duplicate/new bank state
    # apply 30k threshold
    # write final status
    # commit transaction

    if payload.monthly_deposits >= 30000:
        return {"status": "assign_rep_and_send_docs"}

    return {"status": "mark_low_revenue"}
Enter fullscreen mode Exit fullscreen mode

That gives you a workflow people can reason about.

It also makes debugging possible when something goes wrong at 9:12 a.m. on a Monday.

Where AI does help

I’m not arguing against LLMs here.

I’m arguing against giving them the wrong job.

Good uses in this flow:

  • extracting fields from ugly broker emails
  • parsing scanned PDFs or OCR output
  • summarizing long email threads for a rep
  • drafting a reply asking for missing docs
  • flagging low-confidence extractions for human review

Bad uses in this flow:

  • duplicate detection when the criteria are known
  • rep assignment when the threshold is explicit
  • bank routing when policy is fixed
  • deciding whether CRM state “probably means” something

The moment a rule can be written down, it should stop being an LLM decision.

The cost problem gets ugly fast

There’s another reason to avoid agent-first design: cost creep.

I saw another Reddit comment from someone using OpenClaw who said summarizing the last 10 emails with Claude 4.6 Sonnet cost about $0.25.

That sounds tiny.

Until your “agent” is doing that kind of work all day across:

  • inbox triage
  • CRM re-checks
  • duplicate review
  • status summaries
  • follow-up drafts
  • lead routing decisions that should have been simple SQL or code

That’s how teams end up saying their agent stack burns tokens faster than expected.

The model is doing office work your rules engine should be doing for free.

This is exactly why predictable pricing matters if you’re running automations 24/7. If your workflows call models constantly, per-token billing turns every design mistake into a monthly surprise. Standard Compute is interesting here because it gives you an OpenAI-compatible API with flat monthly pricing, so you can afford to use models for the messy extraction layer without constantly watching token spend. That doesn’t mean you should waste LLM calls on deterministic routing. It means you can use AI where it actually helps and keep the rest of the pipeline boring.

Agent-first vs automation-first

Approach What usually happens
Automation-first Deterministic branching, explicit thresholds, atomic writes, easier debugging
Agent-first More token usage, inconsistent decisions, harder audits, race-condition blind spots
Hybrid LLM for extraction/summaries, code for rules and state transitions

If you remember one thing, make it this:

Using an LLM for extraction is not the same as handing control to an agent.

Those are completely different design choices.

A concrete test

Before you add an AI agent to a workflow, ask:

What part of this flow is genuinely ambiguous?

If the answer is:

  • “the email is messy”
  • “the PDF format is inconsistent”
  • “the broker note is hard to parse”

Use Claude, GPT-5, Grok, or Qwen for extraction.

If the answer is:

  • “check the CRM”
  • “apply the $30k rule”
  • “avoid duplicates”
  • “assign the right rep”
  • “route to the right bank”

You do not need autonomy.

You need explicit logic.

My opinionated version

Most underwriting intake automations are not agent problems.

They are data integrity problems wearing an AI costume.

The messy-input layer is where AI earns its keep.

The state-transition layer is where software engineering still wins.

So if you’re building this in n8n, Make, Zapier, OpenClaw, or custom code, keep the model on a short leash:

  • extract
  • classify uncertainty
  • draft summaries
  • stop there

Then let your rules engine do the real work.

That may be less exciting than saying you built an autonomous underwriting agent.

It also sounds a lot more like something I’d trust with real leads.

Top comments (0)