ChatFin/Build Accounts Receivable Aging with Claude

How to build accounts receivable aging using Claude

By Ashok ManthenaPublished 5 Nov 202610 min read
Three rows of open_invoices.csv (customers C09, C10 and C11, invoices INV-30027, INV-30028 and INV-30029) go into Claude. The same three customers come out in collections.csv: C09 second notice, C10 reminder, and C11 a call with a credit hold. A note reads 12 of 12 customers matched our reference answers.
You need
Open invoices, customers and payment history, as three CSV files
Tested with
Claude Sonnet 5.5, made-up data, 5 Nov 2026
Result
12 of 12 customers matched our reference answers

Before you start

At month end somebody in receivables sorts the open invoices by how late they are, works out how much to set aside for bad debt, and tells each collector who to chase and how hard.

Most of it is a date subtraction and a table of rates. It is the kind of report that waits for the ERP team. On 5 Nov 2026 we wrote the six rules in plain English and Claude wrote the program.

Our file is small: 31 open invoices, 12 customers and 45 rows of payment history. Even so, it forces choices. Is an invoice paid exactly 15 days late "more than 15 days" late?

Does a credit memo reduce the bucket? Should a disputed invoice that is 113 days late make the collector escalate, or does the dispute take it out of the chase?

The rules say nothing about partial payments, unapplied cash, several currencies, parent accounts or promises to pay. Each would be another rule to write and keep.

Our view is that mid size and large companies should not build and maintain this.

Whoever wrote the script has to explain why a customer is on hold and how the allowance was reached, and the rates and limits sit in code. For the trade-off, read Build vs Buy: Finance AI Agents in 2026.

What you need

An ERP connection

You need the open invoice list with due dates, amounts and a dispute flag, the customer list with credit limits, and the payment history for invoices already paid.

Check how your ERP exports all three, and what its API terms allow before you read them live. Collectors then need the result in the place they work.

Our script reads three CSV files and writes two. It sends nothing to anyone.

The data points

Columns in open_invoices.csv, customers.csv and payment_history.csv
ColumnUsed for
invoice_no, customer_idOne line per invoice. Group by ID, never by customer name
due_dateDays past due and the bucket. Not the invoice date
open_amountNegative for a credit memo
disputedY or N. A dispute removes the invoice from the action, but not from the aging, the allowance or the hold
credit_limitThe credit hold test
due_date, paid_date in the historyThe slow payer test

A plan, broken into steps

Attach open_invoices.csv, customers.csv and payment_history.csv and paste this.

Prompt 1: plan
I work in the accounts receivable team. I want a small tool that ages our open invoices and tells the collectors what to do at month end.

I have three files:
- open_invoices.csv: invoice_no, customer_id, customer, invoice_date, due_date, open_amount, disputed (Y or N). A negative open_amount is a credit memo.
- customers.csv: customer_id, customer, credit_limit.
- payment_history.csv: customer_id, invoice_no, due_date, paid_date for invoices already paid.

The report date is 31 Oct 2026. Our policy:
1. Days past due = report date minus due_date. An invoice is not past due when that is 0 or less.
2. Aging 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 on the total of each bucket: Current 1%, 1 to 30 5%, 31 to 60 20%, 61 to 90 40%, over 90 75%. Round each bucket's allowance to the cent. Disputed invoices are in the aging and in the allowance like any other.
4. Collection action for each customer comes from its oldest past due invoice that is not disputed: 1 to 30 "reminder", 31 to 60 "second notice", 61 to 90 "call", over 90 "escalate". No such invoice means "none".
5. A customer is on credit hold when the total of all its past due open amounts, disputed or not, is more than its credit limit.
6. A customer is a slow payer when it has three or more paid invoices in payment_history paid more than 15 days after the due date.

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 and said what could go wrong in nine of them. It found that eight of Harbor Tools' nine invoices sit on the bucket edges, and said it would use them to test the boundaries.

It saw that the Current bucket totals 85,950.50, so 1% is exactly 859.505, a half cent, and asked how to round.

It saw two customers hiding behind a dispute: Cascade Marine owes 8,800.00 past due but gets "none", and Brightway Dental gets a mild "reminder" while a disputed invoice 113 days late sits beside it.

It got one number wrong. It said the payment history has 42 paid invoices, and the file has 45 rows.

After running the script, Claude also corrected its own hand check: it had counted two slow payers, and the script found a third, Summit Peak Outdoor, with three invoices paid 16 days late.

It then listed five open points. Claude said two of them change which customers get flagged. One is:

  • Does a payment exactly 15 days late count as "more than 15"? Six of Kestrel Logistics' paid invoices and three of Maple Row's were exactly 15 days late, so this one word decides whether those two customers are slow payers.
  • Can a credit memo be the oldest past due invoice for the collection action? Claude proposed to skip it, since you cannot chase a customer for a credit. On our file it changes nothing.

Settle before relying on it. We did not answer them. We told Claude to use its plan, and it followed the wording as written and used its own suggestion for the rest. Your head of collections decides all five, and the rounding rule.

Ask Claude to build it

Prompt 2: build and run
Good. Use that plan. Write one Python script, standard library only, that reads the three files 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. collections.csv has one row per customer: customer_id, action, credit_hold (Y or N), slow_payer (Y or N). Use exact decimal arithmetic for money. Never change my files. Run it, then show me the aging totals by bucket, the allowance by bucket and in total, and every customer whose action is not "none", or who is on credit hold, or who is a slow payer.

Claude Sonnet 5.5 (claude-sonnet-5-5) ran both prompts on 5 Nov 2026. The first run took the prompts one at a time, as two turns. The script is 187 lines of Python, standard library only, with money as Decimal.

It stopped with a message instead of guessing if a date, an amount or the dispute flag was malformed, an invoice number repeated, or a customer was missing.

It checked that the five bucket totals added up to the 216,900.50 open balance. The allowance rates are the ones in our prompt, from 1 percent for Current up to 75 percent for over 90 days. Here is the aging and the allowance:

Aging and allowance by bucket
BucketOpenAllowance
Current85,950.50859.51
1 to 30 days32,450.001,622.50
31 to 60 days41,200.008,240.00
61 to 90 days36,000.0014,400.00
Over 90 days21,300.0015,975.00
Total216,900.5041,097.01

Ten of the twelve customers needed attention:

Customers with an action, a hold or a slow payer flag
CustomerActionCredit holdSlow payerNote
Maple Row HardwareSecond noticeYesNo21,000.00 past due against a limit of 20,000
Pine Street StudioCallYesNo6,200.00 past due against a limit of 6,000
Harbor ToolsEscalateNoNoEight of its nine invoices sit on bucket boundaries
Kestrel LogisticsEscalateNoNoSix paid invoices, each exactly 15 days late, so not a slow payer
Atlas Cabinet WorksCallNoNo
Brightway DentalReminderNoNoA disputed invoice is 113 days past due but is skipped for the action
Summit Peak OutdoorSecond noticeNoYesA credit memo of 1,400.00 is netted into its 31 to 60 bucket
Greenleaf SupplySecond noticeNoYes
Lumen OpticsReminderNoNo
Orion RetailNoneNoYesThree invoices paid 22 days late, nothing past due now

The other two, Northline Foods and Cascade Marine, have action "none". The collections file does not show disputes, so a collector who sees "none" for Cascade Marine cannot tell that 8,800.00 is waiting on a dispute.

Where to run it

Receivables aging is a month end job, but collectors work from it every day.

They need it where they already work, with the dispute status visible, and the person who owns the allowance needs a record of what each month's run said. A hosting service such as Vercel is one option. Nothing here was hosted.

If you would rather buy it

ChatFin's build or buy page says it reads through governed feeds and writes back only drafts a person approves. We did not run this policy through ChatFin.

ChatFin also has pages titled How to Build AI Agents for AR Collections, Step by Step and Accounts Receivable Automation with AI: Guide.

Test it before you trust it

1. Plant the answer and keep the key

We built the 31 invoices so that every bucket edge, both holds, three slow payers and the disputed cases appear, and our reference code produced the expected answers. The key was not in Claude's folder.

All 12 customers matched on every field, and the allowance total matched our reference too. A second run, in a fresh session with the same two prompts answered in order, wrote a 189-line script with the same results.

Made-up data. The key comes from our own reading of the policy, and we built the invoices to hit its edges. A match shows the script follows the written rules on these customers. It says nothing about your portfolio.

2. Try the edges of each rule

We ran 25 single-customer files through the first script. The table groups them into ten rows.

Edge case results
What we sentWhat the script did
An invoice due on the report date, then 30, 31, 60, 61, 90 and 91 days past dueCurrent, 1 to 30, 31 to 60, 31 to 60, 61 to 90, 61 to 90, over 90
Only a disputed invoice is past due; a disputed one at 91 days beside an undisputed one at 10 daysAction "none"; action "reminder". The dispute still sits in the over 90 bucket and the allowance
A credit memo, 91 days past due; a credit memo only, 40 days past dueIt lands in its own bucket. The allowance for that bucket goes negative: -75.00 and -20.00
Past due of exactly the credit limit; 0.01 over itNo hold; hold
A disputed invoice that takes past due over the limitHold. Disputed amounts count towards it
Three paid invoices 16 days late; exactly 15; two at 20; three paid earlySlow payer; no; no; no
A bucket of 85.50 at 1%0.86. A half cent rounds up
An invoice for a customer not in the customer fileStopped with a message naming the invoice. No output
Disputed typed yes; amount typed 1,000.00; date typed 01/10/2026; a repeated invoice numberStopped with a message naming the invoice. No output
No open invoices at allRuns. One row of zeros per customer

Every boundary the policy states came out as written. Two outcomes to take to your controller: a credit memo with no invoices around it produces a negative allowance, and the exact-15-day rule decides a flag.

3. Compare it with a second implementation

We wrote our own version of the rules and made 5,000 random invoices across 3,000 customers, with credit memos, disputes and 2,500 payment rows. The two agreed on every bucket, every hold, every slow payer flag (11 customers were slow payers) and the allowance total.

They disagreed on the action for 42 customers, and all 42 are the same case: the customer's oldest undisputed past due line is a credit memo. Our version lets it set the action. Claude's script skips it, as Claude said in the plan.

4. Take the gaps to your head of collections

Exactly 15 days, credit memos as the oldest line, rounding, how a dispute shows to collectors, and whether slow payer should change anything. As written, it changes nothing. Add your answers to the prompt and run the same files again.

Where ChatFin fits

The script shows how far three files and six rules get you in a sitting. Around it you still need the feed from the ERP, a list collectors can work from, and a person to change the rules when the credit policy changes.

ChatFin's build or buy page lists a governed connection and an approval workflow among what you get when you buy (Build vs Buy: Finance AI Agents in 2026).