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).
- ReadLoad the list
- CleanValidate, de-duplicate
- EnrichRead company site
- ScoreFit against the ICP
- RouteCRM, nurture or archive
- DraftFirst email for review
Results
Press Run the pipeline to process the sample list.
| Company | Contact | Score | Tier | Next step |
|---|
Rejected rows
Lead detail
Select a row to see why it scored the way it did, and the drafted email.
Why this score
Next step
Email draft (a person reviews it before sending)
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.