This is a guide to scoring leads with Claude Code so that the same file gives the same ranking on every run.
We’ll go through one example step by step: Callowmere, a call-coaching tool for sales teams at US software and services companies with 50 to 1,000 employees.
Say you have 5,000 leads. The rules remove 1,150, hold 700 until more data comes in, and give the other 3,150 two scores: fit and timing. 260 companies score high on both and get personal outreach from a rep. 2,890 go into automated sequences.
This guide is for founders, GTM (go-to-market) engineers and anyone who ranks accounts for a sales team. It starts where your lead list ends: a CSV file with one row per company. My TAM playbook covers how to build that list. If you already score in a spreadsheet, start at step 2.
Who does what
Claude Code writes the rules, and Python applies them. Every job goes to the one that does it best:
| Job | Who does it | Why |
|---|---|---|
| Turn your notes, wins and losses into rules | Claude Code, approved by you | It’s good at finding structure in messy notes |
| Write example rows with the expected result | Claude Code, checked by you | They become tests |
| Read text into a column (“is this job post a sales role?”) | Claude Code plus a second reader, with a quote | Reading is what models do well |
| Apply the rules, add up the scores, sort | Python | Same input, same output |
| Count, report, compare rule versions | Python | Nothing to interpret |
| Check rows by hand | You | Someone has to decide what a good lead is |
The rules live in a file called rules.yaml, with a version number. The example rows live in examples.csv. Every run starts by scoring the examples. If one lands in the wrong group, the run stops before a real row is touched.
1. Test whether your current scoring gives the same answer twice
If a model scores your leads today, run this test first. Take 200 rows. Ask Claude Code to rank them in two fresh sessions with the same prompt. Count how many of the top 50 appear in both lists.
Every company outside the overlap is one your reps would or wouldn’t call, depending on which run they got.
Three reasons to keep the model away from the scores:
- A model varies between runs. Language models choose each word with some randomness. Even at the lowest randomness setting, Claude doesn’t give exactly the same answer every time, and models released after Claude Opus 4.6 don’t let you change the setting at all. And 5,000 rows means batches, so each row gets judged next to whatever else landed in its batch.
- A model fills gaps. On a row with no headcount, it still returns a score, and the missing field turns into a number that looks like data. Python can hold that row until the field is filled. Step 6 calls this group HOLD.
- You can’t trace a score back to a rule. When a rep asks why a company scored 78, the model can write a reason, but it writes it after the fact, and the next run may write another one. You can’t compare two judgments line by line. You can compare two versions of a rules file.
2. Turn every signal into a column
Python can only apply rules to columns. So every signal, a sign that a company may need you right now, becomes a column with a type, a source and a date.
Claude Code can fill most of them with small scripts: job posts from a job-data API like TheirStack or LeadMagic, headcount and new leaders from your people database, industry from the website. For Callowmere the columns are:
- open_sales_roles: sales job posts in the last 30 days for account executives or SDRs (sales development reps, who book first meetings), from job boards and the company’s careers page
- new_leader_days: days since a new VP or head of sales started, or “none”
- industry_fit: core, adjacent or out, read from the website
- sales_headcount: people with sales titles, from a people search
- call_tool_in_ads: yes or no, whether their sales job posts already name a call-recording tool
- employees and is_customer, which only decide who’s in or out
Blank means unknown, and unknown isn’t zero. A row where nobody checked for a new leader is different from a row where someone checked and found none. Write “none” for the second and leave the first empty. The template treats them differently.
Text columns need a quote and a second reader. When Claude Code reads a website or a job post into a column, it returns the label plus the sentence behind it. A label that removes a company, like industry “out”, needs a second read that agrees.
We use Claude Code together with Gemma, a free AI model from Google that runs locally on your computer, as the second reader. A company only goes out when both say no. A wrong “out” is the error nobody looks at again.
3. Write the rules: gates, fit and timing
The rules file has three parts.
It’s written in YAML, a simple text format for settings that you can read without knowing code.
Gates decide who’s in. A gate is a hard rule. A company that fails a gate is out, with the gate’s label as the reason. A gate on a blank value never removes a company. You can’t fail a test nobody ran.
Then give every company two scores. Fit is how closely it matches your best customers, for example its size or its industry. Timing is how urgent it is right now, for example a new job post. Companies high on both get the most personal outreach: a call, an email and a LinkedIn message from one person. The rest go into automated email and LinkedIn sequences.
Why two scores instead of one: a single number mixes them up. A company with a perfect fit and no reason to talk now can end up with the same total as a poor fit that’s hiring. They need different emails, so keep the scores apart.
version: 4
allowed: # text columns: any other value stops the run
industry_fit: [core, adjacent, out]
call_tool_in_ads: ["yes", "no"]
is_customer: ["yes", "no"]
gates: # fail one and the lead is OUT, with the label as reason
- {column: employees, min: 50, max: 1000, label: "outside 50 to 1,000 employees"}
- {column: industry_fit, not_in: [out], label: "industry out"}
- {column: is_customer, not_in: ["yes"], label: "already a customer"}
fit: # how closely it matches your best customers
- {column: industry_fit, in: [core], points: 40, label: "core industry"}
- {column: industry_fit, in: [adjacent], points: 15, label: "adjacent industry"}
- {column: sales_headcount, min: 10, max: 80, points: 40, label: "sales team 10 to 80"}
- {column: call_tool_in_ads, in: ["yes"], points: -20, label: "call tool already in job posts"}
timing: # how urgent it is right now
- {column: open_sales_roles, min: 3, points: 60, label: "3+ open sales roles"}
- {column: open_sales_roles, min: 1, max: 2, points: 30, label: "1 to 2 open sales roles"}
- {column: new_leader_days, max: 120, points: 40, label: "new sales leader"}
high: {fit: 60, timing: 50} # at or above both: personal outreach
4. Let Claude Code write the first rules
You don’t have to write the rules file by hand. Give Claude Code your notes and your closed deals, and let it write the first version. It writes rules and examples, and never a score.
Here’s the prompt I’d use:
You are writing lead-scoring rules. You will not score any lead.
Read:
- icp.md: who we sell to and why
- wins.csv and losses.csv: 10 to 20 closed accounts each, with the reason
- columns.md: every column in leads.csv, its type, allowed values, source and date
Write rules.yaml in exactly the format of rules_example.yaml:
- Gates only for hard reasons to exclude that icp.md names. Never invent a gate.
- Fit rules say how closely a company matches our best customers.
Timing rules say how urgent it is right now. Never mix the two.
- Points only on columns that exist in columns.md. No column, no rule.
- Every rule gets a short label and a one-line reason that cites a win,
a loss or a line from icp.md.
- A blank value means unknown. Never give points for a blank.
Write examples.csv with 20 rows from wins.csv, losses.csv and leads.csv:
all columns, expected_group, and one sentence why. Include 5 obvious
PERSONAL, 5 obvious OUT and 10 rows close to a cutoff.
Then list:
1. Every rule you expect to fire on more than 90% of leads.
2. Every place where my notes contradict each other.
Do not write code.
Read the rules before you run anything. Every rule should make sense to a rep in one sentence.
5. Score with Python
This is the whole engine. Save it as score.py next to your files, install the one library it needs with pip install pyyaml, and run python3 score.py. Claude Code can adapt it to your columns in a minute, and nothing in it calls a model:
"""score.py: apply rules.yaml to leads.csv. Same file in, same ranking out, every run."""
import csv, sys, yaml
from collections import Counter
R = yaml.safe_load(open("rules.yaml"))
ORDER = {"PERSONAL": 0, "SEQUENCE": 1, "HOLD": 2, "OUT": 3} # sort by this, never by name
NEEDED = {r["column"] for r in R["gates"] + R["fit"] + R["timing"]}
def known(v):
return v not in ("", None)
def fires(rule, v):
if not known(v):
return False
if "in" in rule:
return v in rule["in"]
if "not_in" in rule:
return v not in rule["not_in"]
try:
x = float(v)
except ValueError: # "none" means: checked, nothing found
return False
return rule.get("min", float("-inf")) <= x <= rule.get("max", float("inf"))
def points(rules, row):
hits = [r for r in rules if fires(r, row[r["column"]])]
return sum(r["points"] for r in hits), [r["label"] for r in hits]
def score(row):
for col, ok in R["allowed"].items():
if known(row[col]) and row[col] not in ok:
sys.exit(f"{row['domain']}: unexpected {col}={row[col]!r}. Fix the data or the rules.")
fit, fit_why = points(R["fit"], row)
timing, timing_why = points(R["timing"], row)
failed = [g["label"] for g in R["gates"] if known(row[g["column"]]) and not fires(g, row[g["column"]])]
unknown = sorted(c for c in NEEDED if not known(row[c]))
if failed:
group, why = "OUT", failed
elif unknown:
group, why = "HOLD", [f"unknown {c}" for c in unknown]
elif fit >= R["high"]["fit"] and timing >= R["high"]["timing"]:
group, why = "PERSONAL", fit_why + timing_why
else:
group, why = "SEQUENCE", fit_why + timing_why
return {**row, "fit": fit, "timing": timing, "group": group,
"reasons": " + ".join(why), "rules_version": R["version"]}
# 1. The examples written with the rules are tests. One miss stops the run.
misses = []
for e in csv.DictReader(open("examples.csv")):
got = score(e)["group"]
if got != e["expected_group"]:
misses.append((e["domain"], e["expected_group"], got))
if misses:
sys.exit(f"examples failed (domain, expected, got): {misses}")
# 2. Score, then sort with a full tie-break so equal scores never swap places.
rows = [score(r) for r in csv.DictReader(open("leads.csv"))]
rows.sort(key=lambda r: (ORDER[r["group"]], -r["fit"], -r["timing"], r["domain"]))
with open("scored.csv", "w", newline="") as f:
w = csv.DictWriter(f, fieldnames=list(rows[0]))
w.writeheader()
w.writerows(rows)
# 3. Reports: group counts, and how often each rule fires on the scored rows.
groups = Counter(r["group"] for r in rows)
print("groups:", ", ".join(f"{g} {groups[g]}" for g in sorted(groups, key=ORDER.get)), f"(total {len(rows)})")
scored = [r for r in rows if r["group"] in ("PERSONAL", "SEQUENCE")]
for p in R["fit"] + R["timing"]:
share = sum(fires(p, r[p["column"]]) for r in scored) / max(1, len(scored))
note = " <- separates nothing" if share > 0.9 else " <- too rare to judge" if share < 0.01 else ""
print(f"{p['label']:<32} fires on {share:4.0%}{note}")
What it does that a prompt can’t:
- An unexpected value stops the run. “Core” with a capital C is a new value. Scoring it as not core would drop a whole group of rows without a trace.
- An unknown value sends the company to HOLD. It never gets a score from a guess.
- Every row carries its reasons and the rules version, so “why is this company in the personal group?” has its answer in the row.
- Ties break on the domain, so two rows with the same scores keep their order on every run.
6. Put every company into a group and decide where to stop
The template sorts every company into one of four groups. In the example, the 5,000 leads end up like this:
- OUT: 1,150. 640 outside 50 to 1,000 employees, 380 with industry “out”, 130 existing customers.
- HOLD: 700. At least one column the rules need is unknown. These go back to enrichment, never to a rep.
- PERSONAL: 260. Fit 60 or more and timing 50 or more.
- SEQUENCE: 2,890. Everything else that passed the gates.
Inside SEQUENCE, the two scores still tell you something. 1,240 companies have a high fit and no reason to talk now. 410 have a reason to talk now but a weaker fit. 1,240 are low on both.
Set the two cutoffs from your reps’ time. Say two reps each start with 50 new companies a week. That’s 100 a week, so the 260 personal companies last two and a half weeks. If PERSONAL held 1,500 companies, the cutoffs would be too low, and most of those companies would wait months for a call. Raise them until PERSONAL holds a few weeks of work.
Decide where to stop before you see the list. Write down now what comes next, for example the high-fit companies from SEQUENCE as soon as they show timing. Don’t decide it on the day the list runs out.
Score again every week. Job posts close, new leaders stop being new, and other companies start hiring. In my experience the personal group refills often enough that going deep into the low-fit companies rarely pays.
7. Remove rules that fire on almost everyone
A rule that’s true for almost every company separates nothing. Say the first draft of Callowmere’s rules has a fit rule “uses a CRM: +10”. The report shows it firing on 96% of scored rows. All it does is add 10 points to nearly every score.
Software companies with a sales team use a CRM. That’s a description of the market you pulled, so it belongs in the market definition or nowhere.
That’s why the template prints how often each rule fires. Above 90%, a rule gets the flag “separates nothing”. Below 1%, it gets the flag “too rare to judge”. A rule that fires on a few dozen rows can’t show you whether it works yet, so keep its points small until you’ve seen it pay off.
The same thinking applies after a campaign. “Most replies came from software companies” means little if most of the list was software companies. Compare the reply rate inside the group with the rate outside it. If they’re the same, you’ve learned nothing new about who replies.
8. Check the rules by hand, ten rows at a time
Rules only catch the problems you already know about. So read rows yourself, and pick the ten where the rules are most likely to be wrong:
- three just above the personal cutoff
- two just below it
- two from HOLD
- one from each gate that’s new in this version
- two from the middle of PERSONAL
Open the sources for each one (job posts, the leader announcement, the website). Decide the group yourself before you look at the scores. When you disagree, fix the rule, never the row. Then add the row to examples.csv with the group you expected and run again.
Pick ten new rows every round. Rules fixed on the same ten rows you check them with pass that check every time. The rules are ready when three rounds of ten in a row come back clean.
Here’s what a round can find. Ravelstone Freight is in PERSONAL with “3+ open sales roles”. The posts are for account executives who sell truck capacity, a different job from the software sales roles Callowmere coaches. So the column now counts only account executive and SDR roles that sell software or services, and Ravelstone goes into the examples as SEQUENCE.
For every company in OUT because of a text column, open the page behind the quote. The quote has to support the label, and both readers from step 2 have to agree.
Compare versions, so every rule change shows what it moved. Give Claude Code this prompt:
Write tools/diff_groups.py. Read scored_v4.csv and scored_v5.csv, match on domain.
Print a table: old group (rows) x new group (columns), with counts.
For every cell where the group changed, print 5 example domains with old and new reasons.
Exit with an error if a domain is in one file and not the other.
Five mistakes to avoid
- Sorting groups by their names. Say your groups are Hot, Warm and Cold, and you want each company’s best group across its contacts. min() over the names returns “Cold”, because C comes first in the alphabet, and nothing shows an error. Sort through a fixed order, as the template does.
- Reading a blank as zero. An unknown headcount scored as a tiny company fails the size gate. The company disappears without anyone deciding it should.
- Fixing rows by hand. A rep who knows a company is a great fit puts that in a column with a reason. A group typed into the sheet is gone after the next run.
- Signals without dates. “New leader” depends on today’s date. Store the start date and work out the days on every run.
- Asking the model to check the scored list. If it may change groups, it’s the judge again. Let it suggest rule changes, and let the rules do the rest.
Where to start today
You can score your leads without guessing today in three steps:
- Turn every signal into a column (step 2).
- Let Claude Code write the first rules with the prompt from step 4, from your notes and ten won and ten lost deals.
- Score with the Python template and put every company into a group.


