How to build journal entry automation using Claude

- You need
- Cost pool balances, allocation drivers and departments, as three CSV files
- Tested with
- Claude Sonnet 5.5, made-up data, 5 Nov 2026
- Result
- 9 of 9 pool statuses and 30 of 30 department amounts matched our reference answers
Before you start
At month end, a pool of shared cost such as IT, rent or insurance sits in one account, and somebody has to split it across departments and post the entry.
The arithmetic is proportional. The trouble is the pennies: three departments with equal drivers cannot share 100.01, and the entry must still balance to the cent.
It is the kind of job that ends up in a spreadsheet or on a developer's list. On 5 Nov 2026 we wrote the seven rules in plain English and Claude wrote the program.
Our test has 9 pools, 7 departments and 35 driver rows, and it already includes an inactive department, a negative pool, a pool of exactly 100.00 and a pool where every driver is zero.
The rules say nothing about entities, currencies, allocations in several steps where one pool feeds another, or the layout an ERP wants for journals. Each of those would be another rule to write and keep.
Our view is that mid size and large companies should not build and maintain this themselves. The script we got has the month and the memo text written into it, and each change to the method is a change to code. For the trade-off, read Build vs Buy: Finance AI Agents in 2026.
What you need
An ERP connection
You need the month-end balance of each pool account, the driver values for the month (headcount, floor area, tickets or whatever you allocate on), and the list of departments with their expense accounts.
Posting the journal back needs your ERP's own journal format. Check what import file or API it offers, and what its terms allow, before you point an AI tool at it.
Our script reads three CSV files and writes two. It posts nothing.
The data points
| Column | Used for |
|---|---|
pool, pool_name, pool_account, amount | What is being shared, and the account that holds it |
pool, department, driver_value | The share of each department. One row per pool and department |
department, expense_account | Where each share is posted |
active | Y or N. An inactive department gets nothing |
A plan, broken into steps
Attach pool_costs.csv, drivers.csv and departments.csv and paste this.
I work in the accounting team. I want a small tool that prepares our month-end allocation journal entries. I have three files: - pool_costs.csv: one row per shared cost pool (pool, pool_name, pool_account, amount). The amount is what sits in the pool account at month end. - drivers.csv: the allocation driver for each pool (pool, department, driver_value), for example headcount or floor area. - departments.csv: department, expense_account, active (Y or N). Our policy: 1. Allocate each pool's amount to departments in proportion to the pool's driver values. 2. A department marked active = N gets nothing, and its share is spread over the other departments in the pool by their driver values. 3. Round each department's amount to the cent. If the rounded amounts do not add up to the pool amount, put the difference on the department with the largest driver value. If two are tied, use the one whose name comes first alphabetically. 4. A pool whose driver values for active departments add up to 0 is not allocated. Its status is "hold". 5. A pool whose amount is under 100.00 in absolute value is not allocated. Its status is "skip". A pool of exactly 100.00 is allocated. 6. A negative pool amount is a credit. Allocate it the same way, and the journal posts the other way round. 7. Each allocated pool gets one balanced journal entry dated 31 Oct 2026. For a positive pool, debit each department's expense account and credit the pool account for the total. For a negative pool, debit the pool account and credit each department's expense account. Apply the rules in the order above, and give each pool one status. 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 nine steps and said what could go wrong in eight of them. It also gave the answer it expected for every pool, and those figures matched the script later.
For a negative pool, Claude planned to round the absolute value and put the sign back, so the credit mirrors the debit exactly.
It also warned about an easy mistake with credits: keep the amounts positive and flip the side, because keeping negative numbers and flipping the side reverses the entry twice.
Two things went wrong in the plan. We had said "do not write code yet", and Claude told us it had run a one-off calculation on the files to check its reading, and did not save it. We also cannot reproduce its "36 driver rows": the file has 35, and 36 lines counting the header.
It then listed eleven open points. Three of them need an answer before you rely on the output:
- What happens to a held or skipped pool? POOL-MKT (22,500.00) stays in the pool account. Claude thought its zero drivers look like missing data more than a real zero.
- The rounding method. It makes no difference this month, because no share lands on a half cent, but it will some month.
- Which journal layout your ERP expects. Without it Claude would write a plain CSV.
Settle before relying on it. We did not answer them. We told Claude to use its plan, and it used its own default on several. Your controller decides all eleven.
Ask Claude to build it
Good. Use that plan. Write one Python script, standard library only, that reads the three files and writes two files. journal_lines.csv has one row per journal line: entry (ALLOC- followed by the pool), date, account, department, debit, credit, memo. pool_status.csv has one row per pool: pool, status (allocated, hold or skip), allocated_total. Use exact decimal arithmetic for money. Never change my files. Run it, then show me the status of every pool, the allocation for each allocated pool, and check that every entry balances.
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 199 lines of Python, standard library only, with money as Decimal.
It hashed the three input files before and after the run to show it had not changed them. It allocated 7 pools, put 1 on hold and skipped 1. It wrote 37 journal lines in 7 entries, and every entry balanced:
| Pool | Amount | Status | What happened |
|---|---|---|---|
| POOL-IT | 48,250.00 | Allocated | Legacy Ops is inactive, so its driver of 4 is dropped and the rest split 89 ways. |
| POOL-FAC | 31,075.55 | Allocated | Six departments, no rounding difference. |
| POOL-HR | 12,400.00 | Allocated | Divides exactly. |
| POOL-INS | 18,000.01 | Allocated | Three equal drivers leave one cent over. Engineering comes first alphabetically and takes it: 6,000.01. |
| POOL-TRN | -5,300.10 | Allocated, credit | The pool account is debited 5,300.10 and Engineering, Sales and Support are credited. Engineering has the largest driver and takes the extra cent. |
| POOL-TEL | 100.00 | Allocated | Exactly 100.00 is allocated: 25.00 to each of four departments. |
| POOL-SW | 7,777.79 | Allocated | Engineering and Sales tie on 40 and both round up to 3,111.12, one cent too much. Engineering gives it back: 3,111.11. |
| POOL-LEG | 99.99 | Skip | Under 100.00. |
| POOL-MKT | 22,500.00 | Hold | Both drivers are 0. |
Several choices in the output are Claude's own. The memo text and the date are fixed in the script, so next month someone edits the month name as well as the date. A department whose share rounds to 0.00 gets no line. Rounding is half up.
Where to run it
An allocation entry has to be reviewed before it posts. That needs a page where the accountant sees each pool, its status and the entry, a place to hold the driver data so nobody pastes it into a file, and a record of what was posted.
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 through the official API. We did not run this policy through ChatFin.
ChatFin also has pages titled Best AI Agents for Journal Entry Automation in 2026: What to Look For and Accrual Journal Entry Automation: Post and Reverse Automatically with ChatFin.
Test it before you trust it
1. Plant the answer and keep the key
We built the nine pools so that each rule fires at least once, and our reference code produced the expected answers. The key was not in Claude's folder.
All 30 department amounts and all 9 statuses matched, and every entry balanced. A second run, in a fresh session with the same two prompts answered in order, wrote a different 194-line script and matched on the same figures.
Made-up data. The key comes from our own reading of the policy, and we built the pools to hit its edges. A match shows the script follows the written rules on these pools. It says nothing about your drivers.
2. Try the edges of each rule
We ran 23 single-pool files through the first script. The table groups them into ten rows.
| What we sent | What the script did |
|---|---|
| 100.00, 100.01 and 100.02 split over three equal drivers | The first department alphabetically takes the extra cent in the first, gives one back in the second, and all three get 33.34 in the third |
| Drivers 1, 2 and 2 on 200.01 | The two largest tie. The first alphabetically gets the cent: 80.01 and 80.00 |
| 200.02 over three equal drivers, rows listed C, B, A | A gets the cent, 66.68. Row order does not decide it |
| A pool of 99.99, -99.99 or 0.00; then 100.00 and -100.00 | Skip for the first three. The last two are allocated, the negative one as a credit |
| The only department with a driver is inactive | Hold |
| A pool of 50.00 with all drivers at 0; a pool of 500.00 with no driver rows at all | Hold for both. In the first, hold wins over skip because it is checked first |
| An inactive department with a large driver beside two active ones | Its share is spread over the active two |
| A driver of 2.5; a share of 0.001 that rounds to 0.00 | The decimal works. The tiny share gets no line |
| The same department twice in one pool; a negative driver; a department missing from the departments file; a driver for a pool that does not exist | Stopped with a message naming the row. No output files |
Amount typed 1,000.00; active typed yes; a repeated pool row | Stopped with a message. No output files |
Every boundary the policy states came out as written, and bad data stopped the run before anything was written. The script marks a pool with zero drivers as hold, which is what the policy says. Nothing in it says the zeros may be missing data, so read the hold list every month.
3. Compare it with a second implementation
We wrote our own allocation function and made 3,000 random pools across 12 departments, including amounts of 99.99, 100.00, -99.99 and -100.00, zero drivers and inactive departments.
Claude's script gave the same status on all 3,000 (2,655 allocated, 167 on hold, 178 skipped) and the same amount for every department line. The generator and seed are in the edge folder. Our function is ours. The match shows two readings agree, and both could be wrong.
4. Take the gaps to your controller
The rounding method, what to do with held pools, the journal layout your ERP takes, multi-step allocations, and where the month name lives. Add your answers to the prompt and run the same files again.
Where ChatFin fits
The script shows how far three files and seven rules get you in a sitting. Around it you still need the feed for pool balances and drivers, a screen where the accountant reviews and approves the entry, and a person to change the rules when the allocation method changes.
On the build or buy page, ChatFin lists a full audit trail from prompt to prepared payload as part of what you buy (Build vs Buy: Finance AI Agents in 2026).