How the machine is wired
One form post triggers the whole relay: qualify, draft, send, log, notify. Everything below maps one-to-one onto the n8n workflows you can download.
The pipeline
Download SVG diagramQuote form
Next.js · /api/lead
Webhook
n8n trigger · schema-validated
Enrichment
geo, source, dedupe
Claude
score + draft reply
Confidence gate
send or hold for review
confidence ≥ threshold → send
below → human reviews first
Resend
personal reply email
Postgres
leads + activity log
CRM
HubSpot / Pipedrive / GHL
Owner ping
SMS + Slack
This site runs the same logic server-side in Next.js so the demo works with zero infrastructure. The n8n workflows are the production blueprint.
System prompt versioning
Every qualification run is pinned to an auditable SHA-256 prompt hash so scoring behavior never drifts silently.
SHA-256: 3b447b45Last updated: 2026-03-18- v2.02026-03-18T14:30:00Z
#3b447b45ActiveEvidence-grounded qualification + confidence gate enforcement
- Requires verbatim phrase citations for budget, urgency, and intent signals
- Strict JSON-only output contract with zero markdown wrappers
- Explicit confidence scoring for human-in-the-loop approval threshold
- v1.02026-02-04T09:15:00Z
#76d9e03bInitial scoring and email reply prompt
- Basic 0-100 lead scoring and hot/warm/cold classification
- Single-pass email drafting without verbatim evidence extraction
A/B Prompt Experiment
Deterministic 50/50 split comparing Variant A (direct quote + 2 slots) vs. Variant B (consultative scope + trust proof) across 126 leads.
direct-quoteDirect Quote + 2-Slot Calendar
Urgent emergency jobs (plumbing, HVAC, roofing, electrical)
- Leads with a transparent ballpark price band in paragraph 1
- Offers 2 concrete arrival/callback slots to lock intent immediately
- Under 95 words — built to be read on a phone in 12 seconds
Re: Kitchen sink leak — ballpark $650–$950 + 2 slots today
Hi Marcus — saw your furnace died overnight with two kids at home. A diagnostic + emergency repair typically runs $450–$900 (or $4.8k–$6.2k if replacement is needed). We have a licensed tech available: • Today 1:30 PM – 3:00 PM • Tomorrow 8:30 AM – 10:00 AM Reply with the slot that works and we'll lock it in right away.
consultativeConsultative Scope + Trust Proof
High-ticket renovations & multi-week projects (remodeling, landscaping)
- Asks 1 high-leverage scope question to uncover true project complexity
- Includes local license/warranty proof to build trust before pricing
- Offers a 10-minute scoping callback rather than premature quoting
Re: Full kitchen remodel ($40k) — quick scope question + 10-min call
Hi Tom — a full kitchen remodel targeting a March start with a $40k budget is right in our wheelhouse (42 completed Montreal kitchens, 5-year workmanship warranty). One quick question before we map options: are you keeping the existing plumbing/electrical layout, or opening up a wall? Happy to jump on a 10-minute scoping call tomorrow at 10:00 AM or Thursday at 2:00 PM.
Interactive cost & ROI estimator
Slide monthly lead volume to compare LLM + email operating costs against conservative revenue saved by responding in 38 seconds.
Monthly LLM cost
$0.0684
$0.00023 / lead
Email delivery
$0.00
Resend free tier (≤3,000/mo)
Total operating cost
$0.0684
LLM + transactional email
Est. revenue saved
$10,200
~12.0 extra jobs/mo (149123× ROI)
Assumptions: ~480 input + 260 output tokens/lead at $0.15/1M in & $0.60/1M out; 2 emails/lead; conservative +4% conversion lift on an $850 average home-service ticket.
The n8n workflows
Import these JSON files straight into n8n. Each one documents its own retry, dedupe, and gating rules in workflows/README.md.
instant-response.jsonThe 38-second relay: webhook → validate → enrich → Claude → confidence gate → Resend email → Postgres → owner ping.
Download JSONenrichment.jsonFills in what the lead didn't say: geo from IP, service inference from message text, duplicate detection against the last 90 days.
Download JSONfollow-up-sequence.jsonDay-2 nudge and day-5 breakup email, scheduled per lead, cancelled the moment they reply or book.
Download JSONowner-notification.jsonHot leads trigger an instant SMS + Slack message to the owner with the score, the evidence, and a one-tap callback link.
Download JSONThe three rules that make it production-grade
Retry with backoff
Every external call (LLM, email, CRM) retries up to 3 times with exponential backoff before escalating to the owner. A flaky API never loses a lead.
Duplicate detection
Same email + same service within 90 days = the same deal. The workflow updates the existing record instead of creating a twin, so the pipeline never double-counts.
Confidence-gated sending
Below the confidence threshold, nothing sends. The draft is held, the owner gets a review link, and only a human click releases it. The AI proposes; a person disposes.
workflows/README.md
Security & compliance notes
Operational guardrails baked into every API route and workflow.
Per-IP rate limiting & idempotency
All /api/* endpoints enforce 30 req/min per IP (HTTP 429). POST /api/lead supports Idempotency-Key headers so webhook retries never create duplicate leads or send double emails.
Confidence-gated outbound messaging
Drafts below CONFIDENCE_THRESHOLD (default 55) are automatically held for human approval. Demo/test addresses (@example.com, @test.*) never trigger live outbound email.
Minimal PII & zero secret leakage
Only lead name, contact info, and inquiry text are persisted. API keys are server-only environment variables; the app operates in full zero-key demo mode by default.
Auditable prompt & dependency health
GET /api/health reports live status for the data store, Anthropic LLM, Supabase database, Resend email, and n8n webhooks alongside the active SHA-256 prompt hash.
Deployment instructions
Go from zero-key demo to production in under 15 minutes.
Deploy Next.js app to Vercel
Connect the repo on Vercel (Next.js preset). Add ANTHROPIC_API_KEY, RESEND_API_KEY, and Supabase keys whenever you are ready to flip from demo to live.
npm install && npm run buildProvision Supabase Postgres
Run supabase/schema.sql in your Supabase SQL editor to create the leads and runs tables shared between Next.js and n8n.
psql $DATABASE_URL -f supabase/schema.sqlImport n8n workflows on a VPS
Spin up n8n via Docker on a $5–$10 VPS, import the 4 JSON files from /workflows, and set N8N_WEBHOOK_URL.
docker compose up --build -d