kritwish.
  • Work
  • Systems
  • Playbook
  • Career

kritwish mondal, gtm engineer · diagrams sanitized: no customer data, no secrets

← Pipeline

Production

Lead enrichment

  • TypeScript
  • DuckDB
  • LLMs
  • Search and scrape APIs
Before
240–320 s per lead · deadlocks at concurrency 10
Action
TypeScript rewrite: typed single-shot extractors, caching
After
73 s mean · 50/50 at concurrency 40
Verified by
Benchmark run, n=50, 0 errors

The problem

The company sold an AI growth platform to local salons and spas, so outbound meant cold outreach to beauty and wellness businesses. Each lead had to answer three questions. Is it worth contacting? How do we reach the person who decides? Which pain do we lead with? The most valuable field is the owner's first name. It makes the opening line personal, and on a call it gets a rep past the front desk.

The first version was a Python agent pipeline of about 3,500 lines, where tool-calling LLM agents did their own searching. It took 240–320 seconds per lead. It also hung at around concurrency 10 after about 20 leads, on a connection-pool deadlock in its HTTP client.

Constraints

  • Cost per lead had to stay in cents. A lead that fails the ICP check should cost almost nothing.
  • Owner names are easy to get wrong. Many salons are named after their founder, and a model reading brand copy will call the brand voice the owner. A popular stylist in ten reviews isn't the owner either. A wrong name is worse than none.
  • Vendors fail. Search, scrape and social APIs time out. One vendor failing must not fail the lead.
  • Inputs are messy. Rows arrive as place IDs, addresses, or a name plus city and state.

How it works

The routing is plain code. No LLM decides what runs next.

  1. Load. Read the CSV, detect the input type, and give each row a stable key so a stopped run can resume.
  2. Discover. One web search and one Maps lookup run in parallel. One LLM pass pulls the website, socials, rating and category from the search result.
  3. Qualify before spending. A gate checks rating, review count, category and state. The strict ICP profile is 4.0–5.0 stars with 20–50 reviews. A lead that fails stops here, before any scraping.
  4. Scrape. Sitemap, homepage, up to 3 about pages, team and services pages, and Google reviews.
  5. Extract. Single-shot extractors run in parallel: owner from the website, owner from reviews, team page, staff mentions, years in business. There are 12 in the codebase, and each is exactly one call to gpt-4.1-nano. The rule is "LLMs parse. Tools fetch.": code calls each vendor and pastes the result into the prompt, and the model never browses.
  6. Merge in code. The owner name goes through a waterfall (website, then reviews), and each tier carries a confidence score and its sources. A name that matches the business name needs an explicit owner role or backing from reviews. A name from a review only counts if it sits within about four words of "owner" or "founder". Staff nickname merges (Bob and Robert) are checked by code, with a fall back to raw counts if the check fails.
  7. Write out. Enriched and outbound CSVs, per-lead and batch cost logs, and an upsert into a DuckDB leads store keyed by place ID that never overwrites a value with a blank.

Up to 40 leads run at once, with a separate queue per vendor.

A lead is looked up on search and Maps, dropped early if it fails the ICP gate, then scraped, read by single-shot LLM extractors and merged in code into an enriched record for CSV, the leads store and the campaign engine.

One lead through the enrichment pipeline

Receipts

All of these come from one benchmark run, n=50, at concurrency 40, with the permissive gate (all 50 qualified).

  • 50 of 50 enriched, 0 errors, 181 s wall-clock.
  • 73 s mean per lead (median 70.9 s, p90 90.7 s), against 240–320 s for Python: about 3.5–4.4× faster.
  • Owner first name for 43 of 50 (86%), mean confidence 0.82.
  • Email and phone for 50 of 50 (26 emails came with the input).
  • Staff count for 50 of 50. 44 of those are a lower bound from review mentions, and 6 come from a team page.
  • About 7 LLM calls per lead. The batch cost $0.585, about $0.0117 per lead.

Honest negative

This is one run of 50 leads, not a production average. The latency comparison with Python is like-for-like. The cost comparison is not, because Python ran a different set of agents, so I don't claim a cost improvement.

What broke, and what I changed

The Python pipeline is what broke, and I replaced it rather than patching it.

  • The deadlock led to a rewrite. I ported the pipeline to TypeScript, keeping the logic but not the structure. The 50-lead batch now runs at concurrency 40 in about 3 minutes with zero errors.
  • Agents that browsed became extractors that parse. In Python, each agent had search tools and a "max 2 tool calls" rule. Now code fetches each source once and the model only reads it. Cost and latency are predictable, and a failed vendor leaves one field empty instead of failing the lead.
  • I replaced the fragile plumbing. A pickle cache that didn't carry across machines became a JSON cache keyed by content hash. Hard-coded thresholds became YAML profiles. Per-business cost tracking gained a batch roll-up.

What I'd do next

  • Make fetching faster. Discovery and the first scrape phase averaged 22.5 s and 33 s of the 73 s. The LLM extraction phase averaged 2.8 s.
  • Commit the formal side-by-side report. The benchmark script already flags a 2-point drop in fill rate or a 5-point drop in qualified rate. Running it against a frozen Python snapshot would make the latency claim a checked-in artifact.
  • Pin the owner waterfall with fixture tests, because it produces the highest-value field.

Want systems like these at your org?

Message me on LinkedIn