Build a scam detector for your family
Simple rules and a score can flag many common scam messages. Learn to measure what it catches, what it misses and how often it raises a false alarm.
In 60 seconds
Build a scam detector for your family
Simple rules and a score can flag many common scam messages. Learn to measure what it catches, what it misses and how often it raises a false alarm.
How a rule-and-score detector works
- 1
Rules
Each rule looks for one warning sign, using a few keywords or phrases, and has a weight. - 2
Score
Add up the weights of the rules that fire on a message. - 3
Threshold
If the score reaches the threshold, flag the message as "likely scam". - 4
Explain
Show which rules fired, so the person understands why.
| Warning sign | Example words | Why it is suspicious |
|---|---|---|
| Urgency or threat | "blocked today", "will be cut tonight", "arrested" | Pressure stops people from thinking or checking. |
| Asks for a secret code | "share the OTP", "tell your PIN" | Banks and payment apps say they never ask for these. |
| Asks for money or a fee to receive something | "processing fee", "registration fee" | Real prizes and jobs do not ask you to pay first. |
| Too good to be true | "you won", "guaranteed double returns" | Nobody gives big money for free. |
| Unknown link | "click", a web address | Links can lead to fake pages that steal details. |
| Secrecy or a claimed authority | "do not tell anyone", "customs officer" | Scammers pretend to be officials and isolate the victim. |
Misses and false alarms
# Made-up scores from a rule-based detector.
scam_scores = [7, 6, 5, 5, 4, 4, 3, 2] # 8 real scams
normal_scores = [0, 0, 0, 1, 1, 2, 3, 4] # 8 normal messages
for threshold in [2, 3, 4, 5]:
caught = sum(s >= threshold for s in scam_scores)
false_alarms = sum(s >= threshold for s in normal_scores)
print(f"threshold {threshold}: caught {caught}/8 scams, "
f"missed {8 - caught}, false alarms {false_alarms}/8")Test on messages the rules have not seen
- Rules copied from one example message
- Tested only on the messages used to write the rules
- Says "SCAM!" with no reason
- Uses family members' real private messages without asking
- Rules for general warning signs
- Tested on held-back messages, with misses and false alarms counted
- Shows which signs it found and what to do next
- Uses made-up examples, or real ones only with permission and with personal details removed
Where a model could help later
call_model() to ask "which warning signs does this message show?". Keep the rules as a backup, show reasons, and measure the model on the same labelled set before trusting it.Watch and read more
Lab
A rule-based scam scorer that catches at least 8 of 10 made-up scams with at most 1 false alarm on 10 normal messages.
The problem
All messages are made up. The links use .example addresses, which cannot be real websites.
- Run the starter. It has one rule and catches very few scams.
- Add rules to
RULESfor general warning signs: urgency or threats, asking for a code, asking for money or a fee, prizes and big returns, links, secrecy or claimed officials. Each rule is(name, [keywords], weight). Keywords are matched in lower-case text. - Adjust
THRESHOLDand the weights until you catch at least 8 of 10 scams with at most 1 false alarm. - Look at the normal messages that mention an OTP or a bill. Make sure your rules do not flag them. Write two sentences on which mistake you think is worse for your family, and why.
Practice lab
Edit the code and run it. Python runs in your browser — nothing is sent to our server.
No output. Add print(...) to see values.
You are done when
Hard questions
Try to answer before you reveal. If you can answer these, you understood the lesson.
Q1A friend makes the lab pass by adding a rule whose keywords are the first words of each scam message. Why is this a bad detector, even though the check passes?Reveal
It has memorised these exact messages instead of learning warning signs. A new scam with different wording will get no score at all. This is overfitting. To see it, write five new scam messages and five normal ones that the rules have never seen, and measure again. General signs, like "asks for a fee" or "asks for an OTP", carry over to new messages much better.
Q2Your family tool catches every scam in testing but flags a third of normal messages. What will happen in real use, and what would you change?Reveal
People will soon learn to ignore the warnings, so even real scams get ignored. Make keywords more specific (for example "share the OTP" instead of just "OTP"), give weak signs a lower weight so one sign alone does not reach the threshold, and require two signs together for a flag. Then measure misses and false alarms again on held-back messages.
Questions people ask
Why not just use a big AI model for everything?
You can try, but rules are free, fast, run on a phone without the internet, and explain themselves. They are also easy to test. Many good tools combine both: rules for known patterns and a model for unusual cases, with both measured on the same labelled messages.
Where do I get labelled messages?
Write made-up ones based on patterns described by trusted sources such as banks, police and government awareness pages. If family members share real messages, ask first, and remove names, numbers and links before saving them.
What threshold is right?
There is no single right value. Count misses and false alarms at a few thresholds on your labelled messages, and choose with your users. Write the choice and the reason down.
Can scammers get around my rules?
Yes. They change words, spellings and languages. That is why the tool should say "be careful" rather than "safe", why you keep testing with new examples, and why teaching people the warning signs matters more than any tool.
Lesson test
5 questions. Get 3 right (60%) to pass and complete this lesson.