Case study
One person, two channels: merging duplicate leads without merging the wrong people
FunnelTrace is a lead-triage workflow I built for a fictional home-services company. Leads arrive from a web form and from a WhatsApp-style webhook. The same person often writes on both: a form on Monday, a message on Tuesday. If the system treats them as two leads, someone gets two follow-ups, and the score for the second message ignores everything the first one said.
The rules
Every lead is normalized into one shape first, whichever channel it came from. Emails are trimmed and lowercased. Phone numbers are reduced to digits in international form, so +44 7700 900123 and 0044 7700 900123 become the same string.
Then a new lead is compared with the existing ones, in two steps:
1. The email or the phone number must match exactly after normalizing. A matching name alone never creates a merge. 2. The names must also be compatible. "Sarah M" and "Sarah Mitchell" pass. "Dan" and "Daniel" pass. Two different people who share a phone number, such as a couple on one mobile, don't merge if their names clearly differ.
The check for step 2 is deliberately loose about typos and short forms and strict about everything else:
def names_compatible(a: str, b: str) -> bool:
if not (_has_real_name(a) and _has_real_name(b)):
return True # a WhatsApp lead with no profile name has nothing to contradict
ta, tb = _tokens(a), _tokens(b)
if not _first_names_match(ta[0], tb[0]):
return False
if len(ta) > 1 and len(tb) > 1:
return _last_names_match(ta[-1], tb[-1])
return True
The reason is saved
When two leads merge, the system records why, in plain words:
> normalized phone match; name 'Sarah M' ~ 'Sarah Mitchell'
That text is stored on the lead and shown in the live trace. If a merge looks wrong, you can see which rule fired instead of guessing. The merged lead keeps the more complete name, is re-scored with the new message, and keeps every earlier score in its history.
A near miss stays separate. A lead with a similar name but a different email and phone is a different lead.
How I checked it
I wrote a locked set of 10 leads before writing any scoring code, including a cross-channel pair and a near miss, and ran it through the real app. Dedup was correct on all 10 leads in every one of nine eval runs.
What this doesn't cover
- Ten leads is a small sample. It shows the rules do what I intended, not that they catch every real-world case.
- There is no locking. Two leads from the same person arriving at the same instant could race and create two records.
- Phone numbers without a country code can't be resolved. They are compared as the digits given.
- It matches on email and phone only. It doesn't match on name and address, or across more than the two channels I built.
What I'd tell a client
Not everything in an AI workflow should be AI. Merging records is a place where you want the same answer every time and a reason you can read, so I used rules there and kept the model for scoring and drafting, where judgment is the point.
The code from this post is public: https://github.com/hassan91199/funneltrace/blob/main/backend/funneltrace/dedup.py.
If your leads arrive from more than one place and nobody is sure whether "Sarah M" and "Sarah Mitchell" are the same person, book a call with me on Upwork.