---
name: "waterfall-enrichment-router"
description: "Build a waterfall enrichment router: list providers and prices, sample all of them on the same records, compute cost per accepted value for each provider and field, set a call order per field, route records through the providers and stop at the first value above a confidence line, log every attempt, and send unfilled records to review. Use when enrichment is expensive, patchy or untrusted."
---

# Waterfall enrichment router

## Goal
Get the most accepted values per euro or dollar. Try the cheapest good source first, call the next one only when the last one found nothing you trust, and know how much to trust each value. Part of GTM engineering. Fed by: tam-builder, signal-detection-engine, website-visitor-deanonymizer. Feeds: crm-hygiene-pipeline, icp-scoring-model.

## When to use
- A single provider leaves many empty fields.
- Several providers are used, with no order and no cost tracking.
- You cannot say how much a valid email costs.

## Inputs
- Records with at least a company domain, and a person name or profile link for contact fields.
- Fields wanted (work email, phone, title, seniority, headcount, industry, tech stack).
- Providers you may use and their price per lookup. Use only providers your account is licensed for.
- Your confidence line per field.

## Data model
`attempts`: `record_id, field, provider, found (1 or 0), value, cost, confidence, attempted_at`
`providers.json`: `name, fields, cost_per_lookup, charges_on_miss (true or false), confidence_source`
`order.json`: field to ordered list of providers
`resolved`: `record_id, field, value, provider, confidence, status, cost_spent, enriched_at`
Status is `accepted`, `needs_review` or `no_data`.

## Step 1. Define confidence
Each provider reports confidence differently. Convert to a 0 to 1 scale per field:
- Email: provider status mapped (valid 0.95, risky 0.6, unknown 0.4) combined with your own mailbox verification result. A verified-valid email is at least 0.9.
- Phone: line type and match to name and company.
- Title or headcount: age of the data and agreement between two sources.
Write the mapping in `providers.json` so the rule is visible.

## Step 2. Run a sample
Take 200 records that look like your real list. Call every provider for every field it claims to fill. Log each attempt with cost and confidence. This is the one time you pay for all of them.

## Step 3. Compute cost per hit
Run `scripts/waterfall.py analyze attempts.csv`. For each provider and field it gives attempts, hits, hit rate, total cost, cost per hit and average confidence. Cost per hit is total spend (including misses that were charged) divided by hits.
Verify 30 values per provider by hand or with verification. If a provider's verified accuracy is far below its reported confidence, lower its confidence mapping.

## Step 4. Choose the order
Per field, sort by cost per hit, lowest first, after removing providers below your accuracy bar. Exceptions: put a provider first if it is the only one with strong coverage in a region or segment. Write `order.json`.

## Step 5. Route
For each record and field: call provider 1. If a value comes back with confidence at or above the line, accept and stop. If not, call provider 2, and so on. After the last provider, mark `needs_review` if you have a low-confidence value, or `no_data`. Stop calling when a value is accepted. Never call every provider "just in case".
`scripts/waterfall.py resolve results.csv order.json --min-confidence 0.7` shows the rule on answered rows.

## Step 6. Verify before sending
Run email verification on accepted emails before they enter any sending tool (see inbox-infrastructure-stack and deliverability-monitor). Rows with no accepted email go to review or to another channel such as a LinkedIn task or a phone task.

## Step 7. Monitor
Monthly: cost per accepted value by field, hit rate by provider, bounce rate by provider. Re-run a 200-record sample each quarter and compare. Change the order when the data says so. Log changes.

## Tool options
Enrichment platforms with waterfall features, data provider APIs, a spreadsheet-based enrichment tool or a small script in your warehouse. Any of them works as long as you can log each attempt with cost and confidence. If your platform hides per-attempt cost, track spend from invoices per provider against accepted values.

## Output
`resolved.csv`: `record_id, field, value, provider, confidence, status, cost_spent`

## Success metrics
- Fill rate for the fields you need.
- Cost per accepted value, by field.
- Bounce rate of accepted emails.
- Share of records in review.
- Share of spend on the last provider in each waterfall (it should be small).

## Guardrails
- Use providers within their licence and terms. Do not resell or share raw data outside your licence.
- Business contact data for a business purpose. Collect the minimum fields needed.
- Keep `provider` and `enriched_at` on every value so you can answer data subject requests.
- Honour opt-outs and suppression lists before enrichment, not after.
- Do not guess emails by pattern and send to them without verification.
