Work sample
Lost deal reactivation: which of 760 lost accounts are worth a second call.
A weekly play for an SMB software company. It reads a CRM export of every account that did not buy, decides which are worth another try now, who calls them and with what reason, and hands each of five sellers and the appointment setting team a short list every Monday.
The answer
235 of the 760 accounts are worth a second try now. Each has a reason to talk: 134 have a competitor contract ending or a deal that stalled on timing or silence, and 101 showed real interest this year. 150 of the 235 have had no contact for 11 months.
Where every account goes
| Group | Accounts | Who, and when |
|---|---|---|
| Call first: saw a demo, has a reason to talk | 119 | Seller, weeks 1 to 4 |
| Call first: no demo, has a reason to talk | 116 | Appointment setting, weeks 1 to 8 |
| Call next: saw a demo, no reason yet | 85 | Seller, weeks 5 to 8, only if weeks 1 to 4 pay off |
| Email first: no demo, no reason yet | 90 | One email. A click on pricing or a case study moves the account up |
| Wait: lost under 90 days ago | 39 | Same rules once the wait ends |
| Wait: competitor contract runs over 6 months | 23 | Back 6 months before it ends |
| Ask the seller | 27 | Marked unqualified with no reason: the seller answers yes or no |
| Leave out | 261 | Nobody |
Who calls. An account that saw a demo goes to a seller. One that never saw one goes to appointment setting. Never both. 47 callable accounts belong to owners who left the sales team; they go to the seller with the shortest list.
Run it in n8n
Every Monday at 07:00 it reads every lost account and last week's list, writes this week's call list, the email first list (the 74 of 90 with a usable email) and the 45 groups of probable duplicates, and posts each seller's list to Slack. The code inside gives the same rows as the Python sample on the same data and date, checked row by row, and the workflow imports and runs in n8n. Counts on the lines are from the sample run.
What counts as a reason to talk
- A competitor contract that ends within 6 months, or ended in the last 2. 18 accounts.
- A loss on timing or no answer. 116 accounts.
- Interest this year: pricing page, case study, webinar or event stand. 146 accounts, 45 of them with a second reason too.
Contract and timing reasons rank ahead of interest. Inside a group, accounts where the contact is the owner or managing director go first, then the best lead sources.
What is cut. 113 are outside the target markets, 33 are key accounts with their own seller and 9 are customers today. 106 have a clear no on file: no opportunity, not ICP, too small or a chain. Nothing outweighs a clear no, not even a contract ending. Size cuts nobody.
Four rules I chose
Each is one setting. Change it with --set, run again, and the list shows what moved.
- Wait 90 days after a loss. An account that just said no should not get a call the next week. 90 is my judgement; with real history I would set it from how long lost accounts take to come back on their own.
- A 6 month window for competitor contracts. Renewal is decided before the end date, so the call has to come before it too.
- A newsletter click alone is not a reason to call. It shows the account reads the emails, not that it is buying.
- A person reviews probable duplicates. With no website field, the match is on name, country and size. It flags 45 groups, and several are clearly different companies with a common name. That is why nothing merges automatically: a wrong merge could put a customer on a call list.
This week's top 40
5 accounts for each of the five sellers and 15 for appointment setting, each with the reason, an angle and the caller. All 40 come from the call first groups and 39 of the contacts are an owner or managing director. Same input gives the same output, with no AI call or paid tool inside the run. Running it again with last week's list gives 40 new accounts and no repeats.
Nine checks on every run. The run stops if any breaks: one group per account, no account on two lists, no seller over 5, appointment setting at most 15, no excluded market, key account or customer, no clear no, seller accounts saw a demo and setter accounts did not, no opted out or invalid contact on the email list, and nobody from last week.
Running it every week in HubSpot
Every Monday the ranking runs on a fresh export and writes its result to each account through a private app. If a run fails or a check breaks, nothing is written and last week's lists stay.
- Hand out the week. Sets the owner and creates one call task with reason, angle and fit.
- German sequence. For accounts whose competitor contract is ending, the seller calls first and three German mails follow. It stops on a reply or a booked demo.
- Email first. One mail. A click on pricing or a case study moves the account to call first.
- End of wait. After 90 days, or 6 months before a contract ends, the account is ranked again.
- Ask the seller. One task per unqualified account: still unqualified, yes or no, and why.
- Demo booked. Creates the deal, stamps the source and hands a setter's account to a seller.
- Stop. A new deal, a new customer or an opt out removes the account from every list.
Clean data. The lost reason is empty on 245 of 760 accounts, so it becomes a required dropdown with a clear no as a value. The website domain becomes required so the CRM catches most new duplicates.
What it could be worth per quarter
| Group | Demos | New customers | New MRR |
|---|---|---|---|
| The 235, call first | 18 to 36 | 4 to 9 | €6,800 to €13,700 |
| The 85, call next, weeks 5 to 8 | 8 | 2 | €3,300 |
Every rate here is assumed, because the sample has no history: 1 in 10 to 1 in 5 seller accounts take a demo, 1 in 20 to 1 in 10 setter accounts, 1 in 4 demos close, €1,550 MRR per deal. Each is a setting at the top of the script. These accounts already said no once, so the real rate is likely lower than for a first demo.
How I will know. After four weeks the sellers have called the first 119. If fewer than 1 in 10 took a demo, I stop and the 85 are not called. If 1 in 5 did, the high case holds. One weekly dashboard by group, reason and seller shows accounts handed out, reached, demos, deals and new MRR.
How it was built
- I did
- The groups, the reasons, the cuts, the four rules above, the routing and the stop rule after week 4. I checked every number on this page against the output.
- AI did
- Claude Code wrote both scripts from those rules. In production Claude drafts a researched first line for each call, and a seller approves it before it is used.
- Not built
- The private app that writes back to HubSpot, the workflows and the sequence. Specified, not running. The n8n workflow above is built: it reads the lost accounts and last week's list from Google Sheets, writes this week's lists and posts each seller's list to Slack.
- Run it
python3 make_synthetic_lost.pythenpython3 reactivate.py data/lost_accounts.csv --out output. Standard library only.
Synthetic input. Every account and owner is invented to exercise the rules and says nothing about real companies.
Files
The whole folder on GitHub: clone it and run it with plain Python.
The playbook on ModletHub: the same workflow as a step by step guide to set up yourself.
Read reactivate.py here
"""
Lost deal reactivation: which lost accounts are worth a second call this week,
who calls them, and with what reason.
python3 reactivate.py data/lost_accounts.csv --out output
python3 reactivate.py data/lost_accounts.csv --set wait_days_after_loss=60 --out output_60
python3 reactivate.py data/lost_accounts.csv --worked output/top40.csv --out output_week2
Every account gets exactly one group. The top 40 for the week is 5 per seller
and 15 for appointment setting. A seller takes accounts that saw a demo, a
setter takes the ones that never did, never both. Nine checks run at the end
and the run fails loudly if any breaks. Standard library only.
"""
import argparse
import csv
import json
import os
import re
from collections import Counter, defaultdict
from datetime import date
# ---- settings (each is one rule; change it with --set name=value) ------------
S = {
"today": "2026-10-14",
"wait_days_after_loss": 90,
"contract_window_days": 183, # competitor contract ends within 6 months
"interest_days": 365, # interest this year
"per_seller": 5,
"setting_cap": 15,
# impact estimate, assumed rates
"seller_demo_rate_low": 0.10, "seller_demo_rate_high": 0.20,
"setting_demo_rate_low": 0.05, "setting_demo_rate_high": 0.10,
"next_demo_rate": 0.10,
"win_rate": 0.25,
"mrr_per_deal": 1550,
}
SELLERS = ["Seller A", "Seller B", "Seller C", "Seller D", "Seller E"]
TARGET_COUNTRIES = {"Germany", "Austria", "Switzerland"}
CLEAR_NO = {"no opportunity", "not icp", "too small", "chain"}
STRONG_INTEREST = {"pricing page", "case study", "webinar", "event stand"}
SOURCE_RANK = {"referral": 0, "inbound demo request": 1, "event": 2, "partner": 3, "outbound": 4}
DECISION_MAKER = {"owner", "managing director"}
GROUPS = [
"Call first: saw a demo, reason to talk",
"Call first: no demo, reason to talk",
"Call next: saw a demo, no reason yet",
"Email first: no demo, no reason yet",
"Wait: lost under 90 days ago",
"Wait: competitor contract runs over 6 months",
"Ask the seller",
"Leave out",
]
def days(a, b):
return (a - b).days
def reasons(r, today):
"""Return (reason list, rank). Rank 0 is contract or timing, 1 is interest."""
out = []
if r["competitor_contract_end"]:
to_go = days(date.fromisoformat(r["competitor_contract_end"]), today)
if -60 <= to_go <= S["contract_window_days"]:
out.append(("competitor contract ends " + ("soon" if to_go >= 0 else "recently"), 0))
if r["lost_reason"] in ("timing", "no answer"):
out.append((f"lost on {r['lost_reason']}", 0))
if r["last_engagement"] in STRONG_INTEREST and r["last_engagement_date"]:
if days(today, date.fromisoformat(r["last_engagement_date"])) <= S["interest_days"]:
out.append((f"{r['last_engagement']} this year", 1))
return out
def classify(r, today):
if r["country"] not in TARGET_COUNTRIES:
return "Leave out", "not a target market"
if r["key_account"] == "yes":
return "Leave out", "key account, own seller"
if r["is_customer"] == "yes":
return "Leave out", "customer today"
if r["lost_reason"] in CLEAR_NO:
return "Leave out", f"clear no on file: {r['lost_reason']}"
if r["lifecycle"] == "unqualified":
return "Ask the seller", "marked unqualified, no reason given"
if days(today, date.fromisoformat(r["lost_date"])) < S["wait_days_after_loss"]:
return "Wait: lost under 90 days ago", "lost recently"
if r["competitor_contract_end"]:
to_go = days(date.fromisoformat(r["competitor_contract_end"]), today)
if to_go > S["contract_window_days"] and r["lost_reason"] not in ("timing", "no answer"):
return "Wait: competitor contract runs over 6 months", "contract ends later"
why = reasons(r, today)
demo = r["saw_demo"] == "yes"
if why:
return (GROUPS[0] if demo else GROUPS[1]), "; ".join(w for w, _ in why)
return (GROUPS[2] if demo else GROUPS[3]), "no reason yet"
def sort_key(r):
why = reasons(r, TODAY)
best = min((rank for _, rank in why), default=2)
return (best, r["contact_role"] not in DECISION_MAKER, SOURCE_RANK.get(r["lead_source"], 9), r["account_id"])
def angle(why):
if "contract" in why:
return "Their contract is ending: offer a side by side before they renew"
if "timing" in why:
return "They said not now: ask what changed since"
if "no answer" in why:
return "The thread went quiet: reopen with one new reason"
return "They looked again this year: ask what they were checking"
def norm(name):
return re.sub(r"[^a-z]", "", name.lower().replace("gmbh", "").replace("co kg", "").replace("ag", ""))
def main():
global TODAY
ap = argparse.ArgumentParser()
ap.add_argument("export")
ap.add_argument("--out", default="output")
ap.add_argument("--set", action="append", default=[])
ap.add_argument("--worked", help="last week's top40.csv, so nobody gets the same call twice")
args = ap.parse_args()
for kv in args.set:
k, v = kv.split("=")
S[k] = type(S[k])(v)
TODAY = date.fromisoformat(S["today"])
with open(args.export, newline="") as f:
rows = list(csv.DictReader(f))
worked = set()
if args.worked:
with open(args.worked, newline="") as f:
worked = {r["account_id"] for r in csv.DictReader(f)}
for r in rows:
r["group"], r["why"] = classify(r, TODAY)
r["caller"] = ("Seller" if r["saw_demo"] == "yes" else "Appointment setting") if r["group"] in GROUPS[:3] else ""
# owners no longer on the sales team: their callable accounts go to the seller with the shortest list
load = Counter(r["owner"] for r in rows if r["group"] in GROUPS[:3] and r["caller"] == "Seller" and r["owner"] in SELLERS)
reassigned = 0
for r in sorted(rows, key=lambda x: x["account_id"]):
if r["caller"] == "Seller" and r["owner"] not in SELLERS:
to = min(SELLERS, key=lambda s: (load[s], s))
load[to] += 1
r["owner"] = to
r["why"] += "; owner left, shared out"
reassigned += 1
# the week's top 40
pool = [r for r in rows if r["group"] in GROUPS[:2] and r["account_id"] not in worked]
top = []
for s in SELLERS:
mine = sorted([r for r in pool if r["caller"] == "Seller" and r["owner"] == s], key=sort_key)
top += mine[:S["per_seller"]]
setting = sorted([r for r in pool if r["caller"] == "Appointment setting"], key=sort_key)
top += setting[:S["setting_cap"]]
for r in top:
r["angle"] = angle(r["why"])
# probable duplicates: same normalised name, country and size; a person decides
groups = defaultdict(list)
for r in rows:
groups[(norm(r["name"]), r["country"], r["employees"])].append(r["account_id"])
dups = [ids for ids in groups.values() if len(ids) > 1]
email = [r for r in rows if r["group"] == GROUPS[3] and r["email_status"] == "ok"]
# nine checks
ids = [r["account_id"] for r in top]
per = Counter(r["owner"] for r in top if r["caller"] == "Seller")
results = {
"one group per account": len({r["account_id"] for r in rows}) == len(rows) and all(r["group"] in GROUPS for r in rows),
"no account on two lists": len(ids) == len(set(ids)),
"no seller over 5": all(v <= S["per_seller"] for v in per.values()),
"appointment setting at most 15": sum(1 for r in top if r["caller"] == "Appointment setting") <= S["setting_cap"],
"no excluded market, key account or customer": all(r["country"] in TARGET_COUNTRIES and r["key_account"] == "no" and r["is_customer"] == "no" for r in top),
"no clear no": all(r["lost_reason"] not in CLEAR_NO for r in top),
"sellers saw a demo, setters did not": all((r["caller"] == "Seller") == (r["saw_demo"] == "yes") for r in top),
"no opted out or invalid contact on the email list": all(r["email_status"] == "ok" for r in email),
"nobody from last week": not (set(ids) & worked),
}
failed = [k for k, ok in results.items() if not ok]
if failed:
raise SystemExit("checks failed: " + ", ".join(failed))
os.makedirs(args.out, exist_ok=True)
cols = ["account_id", "name", "country", "employees", "owner", "saw_demo", "lost_reason", "lost_date",
"competitor_contract_end", "last_engagement", "contact_role", "lead_source", "group", "caller", "why"]
with open(os.path.join(args.out, "all_accounts.csv"), "w", newline="") as f:
w = csv.DictWriter(f, fieldnames=cols, extrasaction="ignore")
w.writeheader()
w.writerows(rows)
with open(os.path.join(args.out, "top40.csv"), "w", newline="") as f:
w = csv.DictWriter(f, fieldnames=["account_id", "name", "caller", "owner", "contact_role", "why", "angle"], extrasaction="ignore")
w.writeheader()
w.writerows(top)
with open(os.path.join(args.out, "probable_duplicates.csv"), "w", newline="") as f:
w = csv.writer(f)
w.writerow(["account_ids"])
w.writerows([[" ".join(ids)] for ids in dups])
counts = Counter(r["group"] for r in rows)
first_s = counts[GROUPS[0]]
first_a = counts[GROUPS[1]]
nxt = counts[GROUPS[2]]
def impact(n, rate):
demos = n * rate
deals = demos * S["win_rate"]
return round(demos), round(deals), int(round(deals * S["mrr_per_deal"], -2))
lo = [impact(first_s, S["seller_demo_rate_low"]), impact(first_a, S["setting_demo_rate_low"])]
hi = [impact(first_s, S["seller_demo_rate_high"]), impact(first_a, S["setting_demo_rate_high"])]
why_counts = Counter()
for r in rows:
if r["group"] in GROUPS[:2]:
for w_, _ in reasons(r, TODAY):
why_counts[w_.split(" this year")[0] if "this year" in w_ else w_] += 1
stale = sum(1 for r in rows if r["group"] in GROUPS[:2] and days(TODAY, date.fromisoformat(r["last_contact_date"])) > 330)
summary = {
"accounts": len(rows),
"groups": {g: counts[g] for g in GROUPS},
"call_first": first_s + first_a,
"reasons_in_call_first": dict(why_counts),
"call_first_no_contact_11_months": stale,
"owner_left_reassigned": reassigned,
"top40": {"sellers": dict(per), "appointment_setting": sum(1 for r in top if r["caller"] == "Appointment setting"),
"decision_maker_contacts": sum(1 for r in top if r["contact_role"] in DECISION_MAKER)},
"probable_duplicate_groups": len(dups),
"email_first_sendable": len(email),
"empty_lost_reason": sum(1 for r in rows if r["lost_reason"] == ""),
"impact_quarter_1": {
"demos": [lo[0][0] + lo[1][0], hi[0][0] + hi[1][0]],
"deals": [lo[0][1] + lo[1][1], hi[0][1] + hi[1][1]],
"new_mrr_eur": [lo[0][2] + lo[1][2], hi[0][2] + hi[1][2]],
"call_next": impact(nxt, S["next_demo_rate"]),
"assumed": {k: S[k] for k in S if "rate" in k or k == "mrr_per_deal"},
},
"checks": results,
"settings": {k: S[k] for k in ("today", "wait_days_after_loss", "contract_window_days", "interest_days")},
}
with open(os.path.join(args.out, "summary.json"), "w") as f:
json.dump(summary, f, indent=2)
print(json.dumps(summary, indent=2))
TODAY = date.fromisoformat(S["today"])
if __name__ == "__main__":
main()