Matching Leads to Invoices
YAML--- name: matching-leads-to-invoices description: Matches marketing leads to finance invoices by verifying location, name, and address correspondence, then records the matched invoice number against the lead. Use when reconciling call-center leads (often voice-transcribed) with field-generated invoices (based on ID/passport data) to confirm service delivery and close the lead-to-billing loop. ---
Given a lead record and a pool of invoice records, find the invoice that matches on location + name + address, then write the invoice number back to the lead.
Lead: { location: "Hotel Marina", name: "Jon Smith", address: "Room 204, Hotel Marina, Palm St" }
Invoice: { location: "Hotel Marina", name: "John Smith", address: "Rm 204, Hotel Marina, Palm Street" }
→ MATCH (fuzzy name match + exact room number + logical address match)
→ Record invoice number on the lead
Progress:
- Step 1: Filter invoices to same location as the lead
- Step 2: Fuzzy-match name between lead and invoice
- Step 3: Match address — strict on unit identifier, logical on rest
- Step 4: Confirm all three checks pass
- Step 5: Record invoice number against the lead
- Step 6: Flag unresolved/ambiguous cases for manual review
Step 1: Location Match (gatekeeper)
- Compare
lead.locationtoinvoice.locationfirst — this is the cheapest filter and narrows candidates before doing name/address work. - Treat location as a hard filter: if location doesn't match, don't bother checking name/address unless no other candidates exist (possible call-center logging error — flag separately).
Step 2: Name Match (fuzzy, not exact)
Leads are often transcribed from voice calls, so expect:
- Phonetic misspellings (Jon/John, Catherine/Kathryn)
- Missing middle names or honorifics
- Transposed first/last name order
Approach:
- Normalize case, strip titles (Mr/Mrs/Dr), trim whitespace.
- Use phonetic/fuzzy matching (e.g., Soundex, Levenshtein distance, or token overlap) rather than exact string equality.
- Accept a match if similarity is high even with 1-2 character/spelling differences.
- If multiple invoices at the same location have similarly-scored name matches, don't auto-resolve — flag for manual review.
Step 3: Address Match (two-tier logic)
Address matching is not a single fuzzy comparison — split it into two parts:
- Unit identifier (strict/exact): room number, villa number, house number, apartment number.
- This must match exactly (allowing for format differences like "Rm 204" vs "Room 204" vs "204").
- This is the strongest signal since it's specific and unlikely to coincidentally repeat.
- Remaining address text (logical/fuzzy): street name, building name, area.
- Allow abbreviation differences (St/Street, Apt/Flat), reordering, and minor spelling variation.
- Don't require exact string match — require that it logically refers to the same place.
A match requires both tiers to pass. A matching street but mismatched room number is NOT a match (likely a different unit/patient at the same building).
Step 4: Confirm All Three
Only record a match when location, name, and address (both tiers) all pass. Partial matches (2 of 3) should be queued for manual review, not auto-matched.
Step 5: Record Result
- Write the matched
invoice_numberonto the lead record. - Log the match confidence/basis (exact vs fuzzy) for audit purposes — useful later if disputes arise.
Step 6: Handle Exceptions
- No candidate at same location → flag as "location mismatch, needs review."
- Multiple equally plausible candidates → flag as "ambiguous match, needs review."
- Never force a match when confidence is low.
Example 1 — Clean match Input:
Lead: location="Grand Hotel", name="Maria Lopez", address="Villa 12, Grand Hotel"
Invoice: location="Grand Hotel", name="Maria Lopez", address="Villa 12, Grand Hotel Resort"
Output: MATCH → invoice recorded. (Unit "Villa 12" exact; "Grand Hotel" vs "Grand Hotel Resort" logically same place; name exact.)
Example 2 — Voice transcription name variance Input:
Lead: location="Palm Villas", name="Ahmed", address="House 7, Palm Villas"
Invoice: location="Palm Villas", name="Ahmad Al-Farsi", address="House 7, Palm Villas Compound"
Output: MATCH → invoice recorded. (Name is a phonetic/partial match, common in call-center voice intake; unit number exact; address logically consistent.)
Example 3 — Unit mismatch, reject Input:
Lead: location="Sunset Apartments", name="Lee Wong", address="Apt 5, Sunset Apartments"
Invoice: location="Sunset Apartments", name="Lee Wong", address="Apt 8, Sunset Apartments"
Output: NO MATCH → flagged for review. (Same name/location/building, but unit number differs — likely different patient or data entry error, do not auto-match.)
Example 4 — Location mismatch Input:
Lead: location="Beach Resort A", name="Fatima Noor", address="Room 101"
Invoice: location="Beach Resort B", name="Fatima Noor", address="Room 101"
Output: NO MATCH → flagged as location mismatch, needs manual review even though name and unit number match.
- Always filter by location first — it's the cheapest and most reliable narrowing step.
- Treat the unit number (room/villa/house) as the strongest identity anchor since it's specific and exact-match-able.
- Use fuzzy/phonetic matching for names by default — exact string match will cause false negatives due to voice-call transcription errors.
- Normalize text before comparing: lowercase, strip punctuation, expand common abbreviations (St→Street, Rm→Room).
- Keep an audit trail of why a match was accepted (which fields matched exactly vs fuzzily) for dispute resolution.
- When in doubt, don't auto-match — route to manual review rather than risk mismatching a patient's invoice.
- Don't require exact name match. Leads come from voice calls; exact matching will miss valid matches constantly.
- Don't fuzzy-match the unit number. Room/villa/house numbers must match exactly — fuzzy logic here causes incorrect patient-invoice pairing.
- Don't skip the location check. Matching only on name+address can produce false positives across different properties with similar naming.
- Don't auto-resolve ambiguous cases. If two invoices at the same location have similar name/address scores, always escalate rather than guessing.
- Don't treat "mostly matches" as a full match. All three criteria (location, name, address) must pass — 2 out of 3 is not sufficient for auto-recording.