ChatFin/Cancelled Subscriptions and Revenue With Claude

Cancelled Subscriptions and Revenue With Claude

By Ashok ManthenaPublished 5 Nov 20267 min read
Contracts inC-08 fee 36,500.00term 1 Jan to 31 Dec 2026cancelled 31 Oct 2026C-13 cancelled on its start dayClaudeRevenue outC-08 October 3,722.04C-08 to 31 Oct 36,500.00C-13 to 31 Oct 7,300.00other reading: 3,100.00, 20.00
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

Columns the cancellation rule uses
ColumnWhat the script does with it
cancel_dateThe last day of the term, if filled
fee, start_date, end_dateThe amount to recognise and the days it runs over
amend_date, amend_remaining_feeNeeded for the one contract that is amended and then cancelled
contract_idRow key, used in every error

Claude's ten-step plan

Prompt 1: 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

Prompt 2: build and run
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:

Seven cancelled contracts under both readings
ContractFee, term and cancel dateShortened term (kept)Old rate stopsNote
C-137,300.00, 1 Jun 2026 to 31 May 2027, cancelled 1 Jun7,300.00 to date20.00 to dateThe whole fee on the first day under one reading, one day of it under the other.
C-3421,900.00, 1 Feb 2026 to 31 Jan 2027, cancelled 30 SepOctober 0.00, to date 21,900.00October 0.00, to date 14,520.00Cancelled before October, so October is zero either way.
C-1614,600.00, 15 Jul 2026 to 14 Jul 2027, cancelled 10 OctOctober 1,659.09October 400.00The first reading is more than four times the second.
C-0836,500.00, 1 Jan to 31 Dec 2026, cancelled 31 OctOctober 3,722.04October 3,100.00The term shrinks from 365 days to 304.
C-2573,000.00, 10 Mar 2026 to 9 Mar 2028, cancelled 31 OctOctober 9,588.98October 3,095.76A two year contract that is recognised in full by 31 Oct.
C-2654,750.00, 1 Jan 2026 to 31 Dec 2028, cancelled 20 JulTo date 54,750.00To date 10,040.83Cancelled in July, October 0.00 either way.
C-2336,500.00 amended 16 Aug to 10,950.00 left, cancelled 20 OctOctober 3,318.18, to date 38,784.53October 1,431.37, to date 25,923.53Amended 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:

Prompt 3: one rule for both
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.

Cancel dates around the rule
What we sentWhat 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 NovShortened term in all seven, the same as our key
Cancelled on the end dateBoth readings agree, 3,100.00 in October
Cancelled the day before the end dateShortened term: October 3,108.52, against 3,100.00 under the other reading
Cancel date in 2028 on a Dec 2027 to Mar 2028 contractZero 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

Bad data and the stop rule
What we sentWhat happened
Cancel date before the start, or after the end, including on the second lineStopped, line named, no file, in both scripts
A date typed 10/10/2026, a fee with a comma, a blank feeStopped at the line
End before start, a date without an amount, a repeated contract_idStopped. 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.