ChatFin/Prepaid Catch-Up for Late Invoices With Claude

Prepaid Catch-Up for Late Invoices With Claude

By Ashok ManthenaPublished 5 Nov 20268 min read
Invoices inPI-053 5 Jun 12,000.00service 1 Feb 2026 to 31 Jan 2027PI-037 1 Apr 5,400.00service 31 Mar to 30 Sep 2026ClaudeCatch-up outPI-053 4 months, 3,945.21June books 4,931.51PI-037 1 month, 29.35April books 909.78
You need
Prepaid invoices with service dates, as CSV
Tested with
Claude Sonnet 5.5, made-up data, 5 Nov 2026, two separate runs
Result
953 of 960 cells matched; 960 of 960 after one change

Five rules, 60 invoices

On 5 Nov 2026 we gave Claude five written rules and one file of 60 invoices, and its script matched our key on 953 of 960 cells; the other seven were blanks where the key had 0.00.

Our rule books the months you missed in the month the invoice arrives, as one catch-up amount.

The CSV columns

Columns the catch-up rule uses
ColumnWhat the script does with it
invoice_dateGives the invoice month. The day of the month does not matter
service_start, service_endBoth days count as service days
amountSpread by days over the service
invoice_idRow key, used in every error message

Claude's seven steps and ten unclear points

Attach your own list of prepaid invoices as a CSV with these columns (our test file had 60 rows) and paste this.

Prompt 1: plan
I work in the accounting team. I want a small tool that works out the 2026 expense for our prepaid invoices, including the invoices that reach us after the service has already started.

I have one file, prepaid_invoices.csv (invoice_id, vendor, description, invoice_date, amount, service_start, service_end, expense_account, prepaid_account). Each row is a vendor invoice for a service we pay for in advance.

Our policy:
1. Spread each invoice over its service period by days. A month's expense is the amount times the days of service in that month, divided by the total days of service. Both service_start and service_end count as service days.
2. Round each month to the cent. The last month of the service takes whatever is left, so the months add up to the invoice exactly.
3. The invoice month is the month of invoice_date, whatever the day. We never book expense in a month before the invoice month. If service months fall before the invoice month, their expense is booked in the invoice month as one catch-up amount, added to that month's own expense.
4. The prepaid balance at a month end is the invoice amount minus the expense booked up to and including that month. Before the invoice month there is no balance.
5. If a date or an amount cannot be read, or service_end is before service_start, stop, say which line is wrong, and write no output file.

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 answered with seven steps and ten unclear points. Four of the ten:

  • whether half a cent rounds up
  • whether the catch-up is the sum of rounded months or one rounded sum
  • whether a service that began in 2024 should put 2024 and 2025 months into 2026
  • what the rule does with an invoice dated in January 2027 for service that began in November 2026

We did not answer any of them, and Claude rounded each month.

A second run, started with no memory of the first, listed seven points and raised the same January 2027 invoice.

A 175 line script, 953 of 960 cells

Prompt 2: build and run
Good. Use that plan. Write one Python script, standard library only, that reads the file and writes prepaid_schedule.csv with one row per invoice: invoice_id, catch_up_months (how many service months fall before the invoice month), catch_up_amount (the sum of their expense), the twelve monthly expense columns named 2026-01 to 2026-12 as booked, balance_2026-10-31 and balance_2026-12-31. Use exact decimal arithmetic for money. Never change my file. Run it, then show me the total prepaid balance at 31 Oct 2026, the total catch-up amount, and the row for every invoice with a catch-up amount above zero.

Both prompts went to Claude Sonnet 5.5 (claude-sonnet-5-5) in Claude Code on 5 Nov 2026, one message each. It wrote a 175 line Python script, standard library only, with money in Decimal, and ran it.

The total prepaid balance at 31 Oct 2026 came to 536,731.40 and the total catch-up to 35,966.37 across 8 invoices, of which 34,629.39 books in 2026 and PI-041's 1,336.98 books in January 2027.

The second run wrote a 213 line script and reached the same two figures. The second run's own day by day check of the balance came to 536,731.34, six cents lower, which it put down to rounding each month.

The catch-up rule on real rows

The rule as we wrote it: We never book expense in a month before the invoice month. If service months fall before the invoice month, their expense is booked in the invoice month as one catch-up amount, added to that month's own expense.

Of the 60 invoices, 14 were dated after their service started. Six of those were dated in the same month the service began, such as PI-006. The rule counts months, so a service that began in the invoice month has no earlier month to catch up. The other eight did:

Late invoices and where their catch-up landed
InvoiceDates and amountCatch-upWhat the schedule did
PI-017Dated 14 Aug, service 20 May 2026 to 19 May 2027, 6,300.003 months, 1,260.00August books 1,795.07: 535.07 for August plus the three missed months.
PI-037Dated 1 Apr, service 31 Mar to 30 Sep, 5,400.001 month, 29.35One day of March lands in April. April books 909.78, of which 880.43 is April itself.
PI-053Dated 5 Jun, service 1 Feb 2026 to 31 Jan 2027, 12,000.004 months, 3,945.21June books 4,931.51: 986.30 for June plus the four missed months.
PI-040Dated 2 Oct, service 1 Jan to 31 Dec 2026, 21,900.009 months, 16,380.00October books 18,240.00 and 3,660.00 stays on the balance sheet at 31 Oct.
PI-024Dated 15 Sep, service 1 Mar to 30 Jun, 3,000.004 months, 3,000.00The service ended before the invoice came. All 3,000.00 books in September.
PI-049Dated 27 Feb 2026, service 15 Nov 2025 to 14 Jan 2026, 2,400.003 months, 2,400.00All of it books in February 2026, though the service was over by January.
PI-045Dated 1 Feb 2026, service 1 Jul 2024 to 31 Dec 2026, 12,000.0019 months, 7,614.83February 2026 books 7,982.44. Eighteen of those months were in 2024 and 2025.
PI-041Dated 10 Jan 2027, service 1 Nov 2026 to 31 Oct 2027, 8,000.002 months, 1,336.98Books in January 2027. Nothing in 2026, though two months of service fall there.

Seven blank cells, then 0.00

Rule 4 said there is no balance before the invoice month. Claude wrote that as an empty cell.

Six invoices are dated after October, so their 31 Oct balance was blank, and PI-041 was also blank at 31 Dec: seven empty cells where the key had 0.00. The second run left the same seven cells empty.

We sent a third message in the same session:

Prompt 3: one change
One change. Before the invoice month, write 0.00 in both balance columns instead of leaving them blank. Save the new result as prepaid_schedule_v2.csv, leave prepaid_schedule.csv as it is, run it, and tell me how many cells differ between the two files.

Claude saved a second file. Seven cells differed from the first, all from blank to 0.00, and the totals did not move. We graded the new file against the key: 960 of 960.

Claude noted that a 0.00 now means either an invoice not yet booked or one fully expensed, and you tell them apart by the invoice month. It also changed the script so that it writes the new file by default.

PI-041 is dated 10 Jan 2027 for service that began on 1 Nov 2026. Two months of service, 1,336.98, fall in 2026, but the rule books nothing until January.

At 31 Dec 2026 the books show no prepaid and no expense for PI-041, an 8,000.00 contract that is already running. Claude raised this itself in its plan.

The same gap sits at earlier month ends: PI-040 is dated 2 Oct, so its 16,380.00 for January to September shows no expense until October.

18 single invoices, then 3,000 random ones

1. Try the dates around the rule

One invoice at a time went through the first script, and a reference program written from the same rules gave the row we expected.

Invoice dates around the catch-up rule
What we sentWhat the script did
Dated the day the service startsNo catch-up
Dated the last day of the month the service startsNo catch-up
Dated the first day of the next monthOne month caught up, as the reference
Dated 31 Oct, service from 1 OctNo catch-up
Dated in the last month of the serviceCatch-up for every earlier month, as the reference
Dated 10 Jan 2027, service all inside 2026Everything books in 2027. Balances blank in both scripts

The first five rows matched the reference.

Of 18 single-invoice cases, the script matched the reference on 17 and stopped on the credit note, which is in the table below. In three of the 17 it left a balance blank.

We then built 3,000 invoices with service start dates from 2024 to 2028 and invoice dates from 60 days before the start to 400 days after. Across 48,000 cells there were no differences in value, and 2,893 cells were blank where the reference had 0.00.

2. Feed it bad data

Bad data and the stop rule
What we sentWhat happened
End date before start date, a blank or typed amount ($5000.00, 5,000.00), a date typed 01/03/2026, a 30 Feb date, a blank invoice dateAll stopped at the line, in both scripts, and neither wrote a file
A bad amount on the second lineStopped, named line 3
The same invoice_id twiceBoth scripts went on and wrote two rows. The second script printed a warning
A credit note of -2,000.00The first script stopped with a Python traceback ("balance goes negative"). The second took it and showed a negative balance

Rule 5 asked for a stop on an unreadable date or amount and on an end date before the start date. Both scripts did that. Neither was told about duplicate ids or credit notes, and the two scripts handled them differently.