ChatFin/Accrual Posted-Date Rule, Built With Claude

Accrual Posted-Date Rule, Built With Claude

By Ashok ManthenaPublished 5 Nov 20268 min read
Three October invoices from invoice_history.csv go into a box labelled Claude Sonnet 5.5. Out come three decisions: V03, posted 31 Oct, no accrual; V09, posted 1 Nov, accrue 8056.74; V22, posted 2 Nov, accrue 9203.10. The caption reads 40 of 40 vendors match the answer key.
You need
Invoice history with posted dates, as CSV
Tested with
Claude Sonnet 5.5, made-up data, 5 Nov 2026, two runs
Result
40 of 40 vendors match our answer key, both journals balance

The rule we tested

An October invoice that reaches the books on 31 Oct is a normal payable. Under the rule we test here, the same invoice posted on 1 Nov or 2 Nov is an accrual at the October close.

The cut-off is the first of six rules in our prompt: "An October invoice (invoice_month 2026-10) counts as received only if its posted_date is on or before 31 Oct 2026."

The cut-off sends an October vendor to "no accrual" or to "accrue" and decides which earlier invoice is the latest one on the books. Rule 6 then sets the two dates on the journal: 31 Oct 2026 for the entry and 1 Nov 2026 for the reversal.

Our file has 40 vendors, one accrued liability account (2100) and one close date.

What you need

The invoice list

You need the vendor invoice list with two dates on every line: the month the service belongs to and the day the invoice was booked. We used a CSV file we generated and did not try the API route.

Columns in invoice_history.csv
ColumnUsed for
vendor_idThe key. One decision per vendor
invoice_monthWhich month the service belongs to. Only 2026-10 is an October invoice
posted_dateThe day the invoice was booked. Compared with 31 Oct 2026
amountThe accrual when the invoice is posted late, or the amount of the latest earlier invoice
expense_accountThe debit side of the journal line

Prompt 1: ask for a plan

Use Claude with file access and code execution, as we did. Give it your invoice list (we attached invoice_history.csv) and paste this. Replace the file name, the column names, account 2100 and the dates with yours.

Our prompt says today is 31 Oct, yet the file holds invoices posted on 1 and 2 Nov. Give the day you run it and keep 31 Oct as the cut-off; we did not test that wording.

Prompt 1: plan
I work in accounting. I want a small tool that works out which vendors need an accrual at the October close, using the date each invoice was posted.

I have one file, invoice_history.csv (vendor_id, vendor, expense_account, invoice_month, amount, posted_date). It lists the vendor invoices on our books, one row per invoice. invoice_month is the month the service belongs to. posted_date is the day we booked the invoice. Today is 31 Oct 2026 and the books for October close at the end of today.

Our rules:
1. An October invoice (invoice_month 2026-10) counts as received only if its posted_date is on or before 31 Oct 2026.
2. A vendor with a counted October invoice gets no accrual.
3. A vendor whose October invoice was posted after 31 Oct 2026 gets an accrual equal to the amount of that invoice.
4. A vendor with no October invoice gets an accrual equal to the amount of its most recent invoice for an earlier month that was posted on or before 31 Oct 2026. If there is no such invoice, the decision is "review" and there is no amount.
5. If a vendor has an invoice for a month before October that was posted after 31 Oct 2026, put "late prior month" in its flag. That invoice is not used for the accrual.
6. The journal entry is dated 31 Oct 2026. It debits each accrued vendor's expense account and credits account 2100 Accrued expenses, one credit line per vendor. A second entry dated 1 Nov 2026 reverses it.

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 before they planned, wrote no code yet, and quoted counts: 176 invoice rows, 40 vendors, 12 invoices posted on 1 or 2 Nov.

Both runs opened with one question: today is 31 Oct, so how can an invoice carry a posted date of 2 Nov? Was the file pulled after the close, or are the dates wrong?

  • Vendor V18 has one invoice, for September, posted on 2 Nov. No earlier invoice was on the books at the close, and Claude pointed out that our rules send the vendor to "review" with a blank amount.
  • Three October invoices were posted on 31 Oct exactly (V03, V16, V29). The first run named them as the rows to check by hand for "on or before".
  • When rule 5 sets the flag "late prior month", is the missing September cost itself accrued? Our rules say only that the late invoice is not used.
  • Does "most recent" mean the latest invoice_month or the latest posted_date? There is no age limit, so a vendor last billed in June would be accrued at the June amount.
  • One debit line per vendor or debits totalled by expense account. 1 Nov 2026 is a Sunday, and the first run noted that it falls in the November period.

We answered none of these and told Claude to use its plan.

Ask Claude to build it

Send this in the same conversation as Prompt 1.

Prompt 2: build and run
Good. Use that plan. Write one Python script, standard library only, that reads the file and writes two files. accruals.csv has one row per vendor: vendor_id, decision (accrue, no accrual or review), accrual_amount, flag, reason. journal.csv has the October entry and its reversal: entry (accrual or reversal), date, account, vendor_id, debit, credit, memo. Use exact decimal arithmetic for money. Never change my file. Run it, then show me the total accrual, the vendors on review, the vendors with a flag, and check that the entry and its reversal both balance.

Claude Sonnet 5.5 (claude-sonnet-5-5) ran both prompts on 5 Nov 2026, one turn at a time, and every reply in both runs came from that model. The first script is 186 lines of Python and the rerun, in a fresh session with the same two prompts, wrote 121 lines.

Both use the standard library and Decimal for money. Both gave the same answer: 23 vendors to accrue for 115,637.02 in total, 16 with no accrual and 1 on review.

Five vendors carry the "late prior month" flag. Each journal entry has 46 lines and balances, and the reversal repeats the entry with debits and credits swapped.

Eight vendors from the October accrual run
VendorInvoice monthAmountPostedDecision
V072026-107,458.022026-10-30no accrual
V032026-109,313.412026-10-31no accrual
V292026-101,751.122026-10-31no accrual
V092026-108,056.742026-11-01accrue 8,056.74
V332026-104,724.072026-11-01accrue 4,724.07
V222026-109,203.102026-11-02accrue 9,203.10
V022026-09679.392026-11-01accrue 642.04, flagged
V182026-091,538.762026-11-02review, flagged

V02 accrues 642.04, the August amount, because its September invoice of 679.39 was posted on 1 Nov. V09 accrues the actual October amount, 8,056.74, because that invoice was already posted when the file was pulled.

How we checked it

1. Plant the answer and keep the key

We generated 40 vendors with posted dates on 30 Oct, 31 Oct, 1 Nov and 2 Nov, and our own code wrote an answer key for them. Among them:

  • 3 October invoices posted on 30 Oct, 3 on 31 Oct, 3 on 1 Nov and 3 on 2 Nov
  • 4 vendors whose September invoice was posted after the close
  • one vendor whose only invoice is an October invoice posted 2 Nov, and one whose only invoice is a September invoice posted 2 Nov

The folder Claude worked in held only the input file, and the key stayed outside it. Both runs matched all 40 decisions, amounts and flags.

The key has no journal lines, so for the two journal entries the check was that each balances and carries the right dates, accounts and total.

The vendor names, amounts and dates are invented, and the key comes from our reading of the rules. The dates were generated without regard to weekends: 31 Oct 2026 is a Saturday.

We do not publish the file or the scripts here, so the figures describe our run and cannot be rebuilt from this page.

2. Try the edges of the rule

We ran 17 single-vendor files through both scripts. The table groups 16 of them into nine rows; the 17th, a vendor whose only invoice is for October and posted 2 Nov, is covered in step 1.

Edge case results
What we sentWhat the scripts did
An October invoice posted on 30 Oct, on 31 Oct, on 1 Nov, on 2 NovNo accrual, no accrual, accrue the invoice amount, accrue the invoice amount
September invoice posted 31 Oct; the same invoice posted 1 NovAccrue September; accrue August and flag "late prior month"
A vendor whose only invoice is for September, posted 2 NovDecision "review", no amount, flagged
An October invoice booked before its own month (posted 15 Sep)Counts as received. No accrual
Two October invoices for one vendor, one posted 30 Oct and one 2 NovFirst run stopped with a message. Rerun: no accrual
The same two October invoices, both posted 2 NovFirst run stopped. Rerun: "review". Our own version takes the first invoice and ignores the second: accrue 700.00
invoice_month typed Oct-2026First run stopped. Rerun read it as no October invoice and accrued the September amount, 600.00, over a counted 700.00 invoice. Our own version made the same mistake
A credit note as the latest earlier invoice; an invoice for NovemberFirst run stopped on both. Rerun: "review" for the credit note, and it ignored the November invoice. Our own version accrued -250.00 for the credit note
posted_date with a time, typed 31/10/2026, or blankBoth stopped with a message naming the line

3. Compare it with our own version of the rules

The same author wrote this version and the key, so agreement shows that Claude's script follows our reading of the rules. We made 20 random files of up to 400 vendors each, 7,984 vendors in all, with invoices for random months and posted dates clustered around the close.

Both scripts agreed with our version on every decision, amount and flag, and every journal entry balanced. The random files hold no duplicates, credit notes or bad months, so they test the date logic on clean data only.

4. Questions for your controller

  1. Does a late-posted October invoice make its actual amount the accrual, or do you want an estimate from earlier months?
  2. Does a September invoice posted on 1 Nov need its own accrual in October, or is the flag enough?
  3. Does your ledger take a reversal dated Sunday 1 Nov, or does it move to Monday?
  4. What should the script do when a vendor has two October invoices with different posted dates?

Add the answers to the prompt and run the same file again.

What ChatFin's build or buy page says

ChatFin's agents write back only drafts a person approves through the official API, 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.