← All work

Case study · AI automation

LeadFlow

A pipeline that takes a raw lead list and returns it cleaned, researched, scored and routed, with a first email drafted for each good lead. It replaces the hours an agency team spends qualifying leads by hand.

This is a demonstration build that runs on invented companies. It is modelled on the lead-research and automation work I do for agency clients, whose data and names stay private. The demo below scores with transparent rules so it can run in your browser with no account; the production version uses Claude to read each company's site (see build notes).

Live demo

14 sample rows, including one duplicate and one broken email address.

  1. ReadLoad the list
  2. CleanValidate, de-duplicate
  3. EnrichRead company site
  4. ScoreFit against the ICP
  5. RouteCRM, nurture or archive
  6. DraftFirst email for review
0Rows received
0Rejected
0Hot
0Warm
0Cold or skipped

Results

Press Run the pipeline to process the sample list.

Lead detail

Select a row to see why it scored the way it did, and the drafted email.

Run log
No run yet.

Try your own lead

Nothing you type leaves your browser. It is scored by the same rules as the list above.

How it works

Six steps, each one checkable

1. Read and clean

Rows with a missing company, a malformed email or a repeat of an earlier row are removed, and the reason is recorded. Bad data never reaches the paid AI step.

2. Enrich

The company's home page is fetched and reduced to plain text. If a site is down the request is retried with a growing delay, then the lead is scored on list data alone.

3. Score

Each lead is judged against a written Ideal Customer Profile. The output is a fixed JSON shape: score, reasons, pain point, opening line. Every score comes with its reasons.

4. Route

Hot leads go to the CRM with a Slack alert. Warm leads join a nurture sequence. Cold leads are archived. Competitors are skipped.

5. Draft

A short first email is written from the evidence found. A person approves it before anything is sent. Nothing goes out automatically.

6. Record

Results are written as JSON and CSV with a full run log. Processed leads are remembered, so running the pipeline twice never contacts anyone twice.

Build notes

Decisions and trade-offs

What is in the repository

  • lib/scoring.js: cleaning, scoring, routing. One file shared by this page and the command line.
  • tools/pipeline.mjs: the pipeline. Demo mode and live mode.
  • tools/test.mjs: 11 automated checks.
  • n8n/leadflow.workflow.json: the same flow as an n8n workflow.
  • data/leads.csv: the invented sample list.

Why it is built this way

  • Structured output so the AI step can never return a shape the next step cannot read.
  • Website text is treated as untrusted. The prompt tells the model to read it as evidence and not to follow instructions inside it.
  • One failed lead does not stop the batch. It is logged and picked up on the next run.
  • Human approval before sending. The pipeline drafts; a person sends.
  • Reasons with every score so the sales team can disagree with it.

Discuss a build like this