ChatFin/AR Aging Buckets and Allowance With Claude

AR Aging Buckets and Allowance With Claude

By Ashok ManthenaPublished 5 Nov 20267 min read
Three of the 150 open invoices in open_invoices.csv go into a box labelled Claude Sonnet 5.5. allowance.csv comes out with the 61 to 90 bucket at 124001.33, over 90 at 432360.46 and a total of 586350.04. The caption reads 28 of 28 customers and 5 of 5 allowances match the answer key.
You need
Open invoices with due dates, as CSV
Tested with
Claude Sonnet 5.5, made-up data, 5 Nov 2026, two runs
Result
140 of 140 customer cells and 5 of 5 allowances match our answer key in each of two runs

The rule we tested

Our prompt gives Claude three aging rules and a table of five rates, and rule 3 is about rounding: "Round each bucket's allowance to the cent, with a half cent rounding up. The total allowance is the sum of the five rounded amounts."

On the edges, an invoice due on the report date is not past due. An invoice 30 days past due is in the first bucket and one 31 days past due is in the second.

Our file has no currency column, so we treated every amount as one currency, with 28 customers and 150 invoices.

What you need

One CSV file

You need the open item list with a due date and a signed amount that shows credit memos as negatives.

Aging by invoice date gives different buckets from aging by due date, so check which one your ERP report uses before you compare. We used a CSV file we generated and did not try the API route.

Columns in open_invoices.csv
ColumnUsed for
due_dateDays past due is the report date minus this date
open_amountNegative for a credit memo. It lands in the bucket of its own due date
customer_idThe grouping for the per customer file
The five ratesThese are our test policy. The page claims nothing about any accounting standard

Prompt 1: ask for a plan

Use Claude with file access and code execution, as we did, and keep both prompts in one conversation. Give it your open item list (we attached open_invoices.csv) and paste this.

Replace the file name, the column names, the report date and the rates with yours; our rates are placeholders.

Prompt 1: plan
I work in the accounts receivable team. I want a small tool that sorts our open invoices into aging buckets at month end and works out the allowance for doubtful accounts.

I have one file, open_invoices.csv (invoice_no, customer_id, customer, invoice_date, due_date, open_amount). A negative open_amount is a credit memo. The report date is 31 Oct 2026. Our rules:
1. Days past due = report date minus due_date. An invoice is not past due when that is 0 or less.
2. Buckets by days past due: Current (0 or less), 1 to 30, 31 to 60, 61 to 90, over 90. A credit memo goes in the bucket of its own due date.
3. Allowance rates are applied to the total of each bucket: Current 0.5%, 1 to 30 2%, 31 to 60 10%, 61 to 90 25%, over 90 60%. Round each bucket's allowance to the cent, with a half cent rounding up. The total allowance is the sum of the five rounded amounts.

Do not write code yet. Break the job into numbered steps. For each step say what could go wrong. Then list anything in the rules that is unclear.

Both runs looked through the file first and wrote no tool yet. The first run went further and worked out two of the allowances in the plan turn.

It found that the 31 to 60 bucket comes to 19,710.575 and the 61 to 90 bucket to 124,001.325, two half cents, and warned that rounding half to even gives a different answer.

Half to even would give 124,001.32 for the second bucket, and our rule says 124,001.33. The rerun counted the same two half cents without giving the totals.

Between them the two runs asked:

  • A credit memo due 105 days ago lowers the over 90 bucket, and with it the allowance at 60 percent of its value, even if the customer's invoices sit in other buckets. Should credits be netted against the customer first?
  • If a bucket total ends up below zero, is the allowance negative or zero? And does "half a cent rounding up" mean toward zero or away from it for a negative amount?
  • The rerun asked whether the file is the position at 31 Oct or at the day it was exported. Today is 5 Nov, and a payment received after month end would already be taken off.

We did not answer these in the run. Both scripts keep a credit memo in its own bucket and give a negative bucket a negative allowance.

Ask Claude to build it

Prompt 2: build and run
Good. Use that plan. Write one Python script, standard library only, that reads the file and writes two files. aging_by_customer.csv has one row per customer: customer_id, current, 1_30, 31_60, 61_90, over_90, total. allowance.csv has one row per bucket and a final row named total: bucket, bucket_total, rate, allowance. Use exact decimal arithmetic for money. Never change my file. Run it, then show me the five bucket totals, the allowance for each bucket and the total allowance.

Claude Sonnet 5.5 (claude-sonnet-5-5) ran both prompts on 5 Nov 2026, one turn at a time. The run records list one call to claude-opus-5-5 beside the Sonnet turns in each run. The first script is 124 lines and the rerun, from a fresh session, is 133.

Both use the standard library and Decimal, and both refuse to write anything if a date or an amount cannot be read. Both have the report date typed in, so change it each month. The allowance came to 586,350.04 on 2,326,780.44 of open items, net of 8 credit memos:

Bucket totals and allowance from the first run
BucketTotalRate (our test policy)Allowance
Current532,246.640.5 percent2,661.23
1 to 30380,821.982 percent7,616.44
31 to 60197,105.7510 percent19,710.58
61 to 90496,005.3025 percent124,001.33
Over 90720,600.7760 percent432,360.46
Total2,326,780.44586,350.04
Eight invoices, seven of them on edge days
InvoiceDueDays past dueAmountBucket
INV-700732026-10-3107,134.15Current
INV-701002026-10-013010,092.681 to 30
INV-700672026-09-30318,895.1431 to 60
INV-700942026-09-0160-2,313.55 (credit memo)31 to 60
INV-700152026-08-31617,771.2161 to 90
INV-701382026-08-029015,053.4861 to 90
INV-701422026-08-01916,357.03Over 90
INV-700592026-06-22131-398.65 (credit memo)Over 90

The scripts do not write a bucket per invoice. The Bucket column here is ours, and the customer totals from both runs match the key built on the same assignment.

How we checked it

1. Plant the answer and keep the key

We built 150 invoices for 28 customers, at least two on each of the days 0, 1, 30, 31, 60, 61, 90 and 91 past due (the credit memos and the random fill add more on some of them), with 8 credit memos in four buckets.

We shaped the data so the 31 to 60 and 61 to 90 buckets land on a half cent.

Our own code wrote the answer key, and the folder Claude worked in held only the input file. Both runs matched all 140 customer by bucket cells, all five bucket totals, all five allowances and the grand total. Of the 140 cells, 93 hold an amount and 47 are zero.

We do not publish the file or the scripts here.

2. Try the edges of each rule

We ran 13 small cases through both scripts. The table groups them into nine rows.

Edge case results
What we sentWhat the scripts did
One invoice each due 0, 1, 30, 31, 60, 61, 90 and 91 days past due (1,000.00 each)Current 1,000.00; 1 to 30 2,000.00; 31 to 60 2,000.00; 61 to 90 2,000.00; over 90 1,000.00. Both scripts, and ours, agree
A credit memo of 200.00 at 91 days, with nothing else; the same at 40 daysAllowance of -120.00 and -20.00. A negative bucket gives a negative allowance
A Current bucket of 1.00 at 0.5%; a 61 to 90 bucket of 0.02 at 25%Both land on a half cent and both scripts round it up to 0.01
A 1 to 30 bucket of -0.25 at 2%-0.01. A half cent rounds away from zero, so "up" is read as "larger in size"
An invoice dated 5 Nov, after the report dateFirst run counted it as Current. The rerun stopped with a message
Due date typed 01/10/2026; an amount typed 1,000.00Both stopped with a message naming the line
The same invoice number twiceBoth stopped. Our own version had no such rule and added the two
A header and no invoices; a zero amount invoiceRuns. Every bucket zero
An amount typed with three decimals, 100.005Both showed a bucket total of 100.00 and gave no warning. The allowance was worked out on 100.005, and the shown total is rounded half to even

3. Compare it with our own version of the rules

We reused the reference function that wrote the key. We made 20 random files of 5,000 invoices each, 100,000 in all, across 300 customers, with 8 percent credit memos and invoices placed on the edge days.

Five buckets in those files landed on a half cent. Both scripts matched our version on every customer cell, every allowance and the total.

What ChatFin's build or buy page says

ChatFin's agents run on the ERP and version you already have, with no database credentials and no migration, and the buy side lists an approval workflow (Build vs Buy: Finance AI Agents in 2026, read on 3 Nov 2026). We did not run this rule through ChatFin.