Cancelled Subscriptions and Revenue With Claude
- You need
- Subscription contracts with a cancel date, as CSV
- Tested with
- Claude Sonnet 5.5, made-up data, 5 Nov 2026, two separate runs
- Result
- 79 of 80 cells matched our key in both runs. The first run reached 80 of 80 after our rule for C-23, which recognises more than that contract's fee
Six rules, 40 contracts
On 5 Nov 2026 we gave Claude six written rules and one file of 40 contracts, nine of them cancelled, and it wrote the script.
The cancellation rule has two readings: what is recognised for the month of cancellation, and what happens to the part of the fee never earned. The scripts matched our key on 79 of 80 cells.
The file has no refund column, and each contract has one cancel date with no reinstatement.
The CSV columns
| Column | What the script does with it |
|---|---|
cancel_date | The last day of the term, if filled |
fee, start_date, end_date | The amount to recognise and the days it runs over |
amend_date, amend_remaining_fee | Needed for the one contract that is amended and then cancelled |
contract_id | Row key, used in every error |
Claude's ten-step plan
I work in the accounting team of a software company. I want a small tool that works out our subscription revenue for October 2026, including contracts that customers cancelled before the term ended. I have one file, contracts.csv (contract_id, customer, start_date, end_date, fee, amend_date, amend_remaining_fee, cancel_date). fee is the subscription fee for the whole term. amend_date and amend_remaining_fee are filled only where a contract was amended, cancel_date only where it was cancelled. Our policy: 1. Revenue is recognised by day over the term. The term runs from start_date to end_date, both days included. 2. Recognised to a date = fee times the days from start_date to that date, divided by the days in the term, rounded to the cent. October revenue is recognised to 31 Oct 2026 minus recognised to 30 Sep 2026. 3. An amendment changes the rate from amend_date. Before amend_date the contract keeps its original rate. From amend_date to the end of the term, amend_remaining_fee is what is left to recognise, spread by day over those days, both days included. 4. A cancellation ends the term on cancel_date, both days included. Nothing is recognised after it. 5. Nothing is recognised before start_date or after end_date. 6. Stop, say which line is wrong, and write no output file if cancel_date is before start_date or after end_date, or if a date or an amount cannot be read. Do not write code yet. Break the job into numbered steps. For each step say what could go wrong. Then list anything in the policy that is unclear.
Claude gave ten steps. Its first question under the unclear points was about rule 4: does the fee shrink to the new term, or does the old daily rate just stop?
It worked C-08 both ways, 3,722.04 for October under one reading and 3,100.00 under the other, and named the six contracts whose October figure moves. It also asked whether a cancelled customer still owes the whole fee, since the answer decides which reading is right.
A second run, started with no memory of the first, gave three options instead of two. The third is a different treatment: the shortened term with September already closed at the old rate, so October carries a catch-up, 9,200.00 for C-08. We answered neither run.
Both scripts kept the shortened term
Good. Use that plan. Write one Python script, standard library only, that reads the file and writes revenue_schedule.csv with one row per contract: contract_id, october_revenue, recognised_to_date (recognised to 31 Oct 2026). Use exact decimal arithmetic for money. Never change my file. Run it, then show me the totals of october_revenue and recognised_to_date, and the row for every contract that has a cancel_date.
The two prompts went into Claude Code on 5 Nov 2026 as separate messages to Claude Sonnet 5.5 (claude-sonnet-5-5). Both runs chose the shortened term, and both added an option that prints the other reading. The first script ran to 205 lines and the second to 211.
Both reported October revenue of 95,927.38 and 725,483.30 recognised to 31 Oct. Our key has 732,117.83 recognised, and the gap is one contract, C-23, below. Under the other reading the same file gives 85,180.58 for October, 10,746.80 less, and 583,417.85 recognised.
Rule 4 on real rows
The rule as we wrote it: A cancellation ends the term on cancel_date, both days included. Nothing is recognised after it.
Seven of the nine cancelled contracts, under both readings:
| Contract | Fee, term and cancel date | Shortened term (kept) | Old rate stops | Note |
|---|---|---|---|---|
| C-13 | 7,300.00, 1 Jun 2026 to 31 May 2027, cancelled 1 Jun | 7,300.00 to date | 20.00 to date | The whole fee on the first day under one reading, one day of it under the other. |
| C-34 | 21,900.00, 1 Feb 2026 to 31 Jan 2027, cancelled 30 Sep | October 0.00, to date 21,900.00 | October 0.00, to date 14,520.00 | Cancelled before October, so October is zero either way. |
| C-16 | 14,600.00, 15 Jul 2026 to 14 Jul 2027, cancelled 10 Oct | October 1,659.09 | October 400.00 | The first reading is more than four times the second. |
| C-08 | 36,500.00, 1 Jan to 31 Dec 2026, cancelled 31 Oct | October 3,722.04 | October 3,100.00 | The term shrinks from 365 days to 304. |
| C-25 | 73,000.00, 10 Mar 2026 to 9 Mar 2028, cancelled 31 Oct | October 9,588.98 | October 3,095.76 | A two year contract that is recognised in full by 31 Oct. |
| C-26 | 54,750.00, 1 Jan 2026 to 31 Dec 2028, cancelled 20 Jul | To date 54,750.00 | To date 10,040.83 | Cancelled in July, October 0.00 either way. |
| C-23 | 36,500.00 amended 16 Aug to 10,950.00 left, cancelled 20 Oct | October 3,318.18, to date 38,784.53 | October 1,431.37, to date 25,923.53 | Amended on 16 Aug, then cancelled on 20 Oct. |
Under the shortened term every cancelled contract without an amendment has recognised its whole fee by the cancel date, even one cancelled on its first day.
The October figures are the month's share under the new term, as if every month had been booked that way. If January to September are already closed at the old rate, the October entry is a catch-up, 9,200.00 for C-08 instead of 3,722.04, which is the second run's option (c).
C-23, the one contract that differed
Claude's outputs match 65 of 80 cells against a key built on the other reading, because 15 cells differ between the two readings. C-23's recognised to date was 38,784.53 in our key and 32,150.00 in Claude's.
Our key spreads the fee over the shortened term, 278 days to 20 Oct, which makes the part before the amendment 27,834.53, and adds the 10,950.00 left. That is more than the 36,500.00 fee.
Claude kept the original 365 day rate up to the amendment, 21,200.00 over 212 days, and added the 10,950.00 left, for 32,150.00. Rule 3 says the contract keeps its original rate before the amendment, and the second run read it the same way.
On 3,000 random contracts, 1,192 of them cancelled and 191 amended and cancelled, the first script differed from our key on 128 contracts. All 128 were amended and cancelled. Every cancelled contract without an amendment matched. We sent a third message:
Keep the cancellation reading you used: the cancellation shortens the term. One new rule for a contract that is both amended and cancelled: the whole contract's term ends on cancel_date. The part before amend_date is the fee spread over start_date to cancel_date at that daily rate, and the part from amend_date to cancel_date is amend_remaining_fee spread over those days. Change the script, run it, and tell me which figures moved.
We told Claude to use our reading. It changed the script and reported one figure moved, C-23's recognised to date, from 32,150.00 to 38,784.53, with the total going from 725,483.30 to 732,117.83. October did not move. That made the script follow our key and corrected no mistake.
We graded the new file at 80 of 80, and the 3,000 random contracts again: no differences. On a test contract amended and cancelled on the same day, the same rule gives 47,278.64 on a 36,500.00 fee.
What we tested
1. Try the dates around the rule
Single contracts went through the first script again, this time checked against a reference for each of the two readings.
| What we sent | What the script did |
|---|---|
| Cancelled on the start date (two contracts), on 30 Sep, on 1 Oct, on 10 Oct, on 31 Oct and on 1 Nov | Shortened term in all seven, the same as our key |
| Cancelled on the end date | Both readings agree, 3,100.00 in October |
| Cancelled the day before the end date | Shortened term: October 3,108.52, against 3,100.00 under the other reading |
| Cancel date in 2028 on a Dec 2027 to Mar 2028 contract | Zero in October, both readings agree |
The table shows ten of the 18 single contract cases. The script followed the shortened term in every case without an amendment.
The three with an amendment followed neither of our readings, the same gap as C-23. A fourth, an amendment dated after the cancellation, stopped the run.
2. Feed it bad data
| What we sent | What happened |
|---|---|
| Cancel date before the start, or after the end, including on the second line | Stopped, line named, no file, in both scripts |
| A date typed 10/10/2026, a fee with a comma, a blank fee | Stopped at the line |
| End before start, a date without an amount, a repeated contract_id | Stopped. The policy did not name these |
All nine bad files stopped with no output written, in both scripts. Rule 6 named the cancel date and unreadable values. Claude added the rest on its own.