How to build flux analysis using Claude

- You need
- Trial balance activity and GL detail, as two CSV files
- Tested with
- Claude Sonnet 5.5, made-up data, 3 Nov 2026
- Result
- The script flagged the same 7 of 15 accounts as the answer key
Before you start
Flux review is the monthly chore of explaining why accounts moved. The arithmetic is easy. The explanations are slow, because each one needs a person to open the journal lines and read them.
Writing a tool for that used to mean a project. On 3 Nov 2026 we had Claude build the first draft of it in a short session, and then we tried to catch it making things up.
Our test has 15 accounts and 72 journal lines for the month. A real ledger often has thousands of lines a month, several entities, a budget column, and a reader who asks a follow-up on every paragraph.
A model can lose track in a file that long, and it should not do the sums in its head, so we split the job: a script reads the data and does the arithmetic, and Claude writes from what the script found.
For a mid size or large company we would not build this in house. Flux explanations run on exceptions: the reclass that moves cost between two accounts, the invoice that belongs to last month, the accrual nobody can support.
Each new exception changes what the application has to look for, and your controller decides what counts as explained.
It took four prompts to build. We expect keeping it trustworthy to take longer: the chart of accounts changes, the ERP export changes, a new kind of exception turns up, and the checker needs a new test each time.
We did not test that part. For the build or buy trade-off, read Build vs Buy: Finance AI Agents in 2026.
What you need
An ERP connection
The trial balance is small, and most ERPs can give it to you. The journal line detail is the large one. For a month it can be thousands of rows, and reading it through an API often means paging through all of them.
Claude only sees the flagged accounts and their largest lines. If your ERP has a mature, documented REST API for ledger lines you can build this. Check its API terms before you connect an AI tool to it.
ChatFin's build or buy page says ChatFin runs on the ERP and version you already have and reads through governed feeds, which moves the upkeep of the connection to the vendor. We used CSV files and did not test a live connection.
The data points
| File | Fields |
|---|---|
| Trial balance activity | account, account_name, type, aug_2026, sep_2026, sep_2025 |
| GL detail for the month | entry_id, post_date, account, account_name, description, amount, source, entered_by, party |
Claude flagged one gap. The GL file holds September only, so it can show what is in September but not whether a line is new. Each paragraph has to say so and name what to check in August.
The script read only some of these columns: it ignored account type, the September 2025 column, the GL account name and the party on each GL line.
A plan, broken into steps
Attach both CSVs and paste this.
I run the monthly flux review. I have two files: - trial_balance_activity.csv: activity by account for Aug 2026, Sep 2026 and Sep 2025 - gl_detail_sep_2026.csv: every September journal line (entry_id, post_date, account, description, amount, source, entered_by, party) My rule: explain every account where September is more than 10 percent and more than 5,000 away from August. For each of those accounts I want a short paragraph for my controller. The paragraph may use only facts that are in the GL file. If the file does not show why an account moved, the paragraph must say that, and say what I should check. Do not write code yet. Break the job into numbered steps. For each step say what could go wrong. Then list anything in my rule that is unclear.
Claude gave six steps:
- Find the accounts that meet the rule.
- Check the GL ties to the trial balance.
- List the September lines behind each flagged account.
- Decide whether those lines explain the move.
- Write each paragraph from the GL only.
- Check the paragraphs before they go to the controller.
Under each step it said what could go wrong. It also warned that the Software and Professional fees accounts are linked by one entry that appears twice, once on each side, and that this is not a duplicate.
It asked nine questions, and three of them mattered:
- How much of a move must the lines cover before you call it explained?
- Should the two accounts joined by one reclass get one paragraph or two?
- Can you supply the August detail, so the paragraph can say what is new?
Open for your controller. We did not answer them. Claude assumed answers to four of the nine and left five open. Your controller answers them before you rely on the output.
Ask Claude to build it
Step 1: a script for the arithmetic
Good. Use that plan. First write one Python script, standard library only, that does the arithmetic and the lookup. It reads both files, finds the accounts that meet my rule, and writes flux_facts.json: for each account the August and September amounts, the change in dollars and percent, and the five largest September GL lines (entry_id, post_date, amount, description, source, entered_by). Do not write any explanations in the script. Run it and show me which accounts it flagged.
We ran all four prompts in Claude Code with Sonnet 5.5 (claude-sonnet-5-5) on 3 Nov 2026. We did not run them in the chat app. The 83 line script flagged 7 of the 15 accounts.
Under the rule, September has to be more than 10 percent and more than 5,000 from August, so Product revenue (+71,500) and Cost of goods sold (+42,900) were left out at 8.5 percent. A rule decides who gets explained, and the biggest dollar moves can miss it.
Step 2: the words, from the script's output only
Now write flux_review.md from flux_facts.json only, one paragraph per flagged account, as in the plan. Every number must come from the JSON and every entry ID you mention must exist in it. Then write check_review.py that tests both of those things, and run it.
Claude wrote one paragraph per flagged account into flux_review.md and a 114 line check script. We compared each paragraph with what we had planted in the data:
| Account | Change | What was in the data | What the paragraph said |
|---|---|---|---|
| 4100 Services revenue | up 37,000, 17.2% on August | Two invoices to Orion Retail, 24,000 and 12,500 | Both invoices are in the paragraph. It says the file cannot show whether Orion was billed in August and asks for that detail. |
| 6110 Bonus expense | up 60,000, 500% on August | One manual entry, JE-3342, a Q3 bonus accrual | It points to JE-3342, sees that it equals the change to the dollar, and asks for the support and approval. |
| 6200 Marketing | up 28,800, 92.9% on August | AP-55120, 27,500, a trade show | It names AP-55120. It also raises AP-49618, 17,604, and asks to check the invoice behind it. |
| 6210 Software subscriptions | up 9,500, 51.6% on August | JE-3318, a 9,000 reclass from professional fees | It says part of the increase is a move between two accounts. |
| 6300 Professional fees | down 8,000, 19.5% on August | The other side of JE-3318, minus 9,000 | It picks out the -9,000 entry as the only line that reduces the account. It stops short of saying the decline is the reclass. |
| 6400 Insurance | down 6,800, 100% on August | No September lines at all, most likely a missing prepaid entry | It says the file cannot show why and asks whether a premium or prepaid amortization entry was expected and not booked. No invented reason. |
| 6500 Freight out | up 19,500, 88.6% on August | AP-55007, 17,900, an invoice dated 29 Aug and posted in September | It quotes the 29 Aug date on the invoice and asks about the August accrual and cutoff. |
In this run no paragraph invented a reason. Six of the seven pointed to the entry we planted. Two of those tied it to the change: Bonus expense says the entry equals the change, and Software subscriptions says part of the increase is the move.
Professional fees stopped short of saying that the decline is the reclass. Where the file did not show the reason, as with Insurance, the paragraph said so and named what to check, which is what the prompt asked for.
One line in our data is odd. AP-49618 carries the party Summit Print but the description says digital advertising. We did not plant that. It came out of our data generator.
The first review said the file did not show the vendor on that line, because Prompt 2 left the party column out of the script's output. The plan had already flagged the mismatch, and the review asked to check the invoice.
Where to run it
This runs once a month on a file you hand it. A script on one laptop is enough for a try.
For close week you want it on a schedule, reading the ledger by itself, with the paragraphs landing where the controller works and each edit recorded. A hosting service such as Vercel is one option. We hosted nothing for this page.
If you would rather buy it
ChatFin's build or buy page lists a full audit trail from prompt to prepared payload on every action. We did not run this process through ChatFin. ChatFin also has a page titled Flux Explanations That Survive a Follow-Up.
Test it before you trust it
1. Plant the drivers, keep the key
We built the data from known causes: a new customer, a manual accrual, a one off trade show, a reclass between two accounts, an invoice dated in the prior month, and an insurance charge that stopped without a reason.
We did not give Claude the list. The table above is the comparison.
Made-up data. We chose the causes. The run shows what the method does with clean, labelled lines, and your ledger is messier.
2. Test the checker, not only the output
The check script passed the review, and that proves little. We made a copy of the review, swapped the amounts of two entry IDs, and wrote that the insurance policy was cancelled.
Both statements are wrong. The check from Prompt 3 passed that copy, because each number exists somewhere in the data, and nothing tested what a sentence claims.
Your check passed a copy of the review where I swapped two amounts between entry IDs and wrote that the insurance policy was cancelled. Both are wrong. The copy is flux_review_bad.md in this folder. Please write check_review2.py that catches both kinds of mistake, run it on flux_review_bad.md and on the real flux_review.md, and show me the output of each. Do not change flux_review.md.
Claude wrote a 264 line second check. It ties each entry ID to its own amount, date, description, source and preparer, and it looks for cause words the lines do not support.
It failed the bad copy on both counts and passed the real review. Then we made six more copies with a different mistake each:
| Mistake we added | The second check |
|---|---|
| A preparer name swapped on a line | Caught |
| A cause added with a listed word: "reflects the peak season" | Caught |
| A cause added with a listed word: "because Orion Retail signed in September" | Caught |
| A wrong September total for one account | Caught |
| An account paragraph removed and replaced with "Insurance is flat" | Caught |
| A cause with no listed word: "The company moved to a new insurer." | Passed |
It caught five of six. The first check, from Prompt 3, already catches two of them, the wrong total and the dropped account, so the second check adds three: the swapped preparer and two added causes.
Those two were caught because the cause used a word on the check's list. The sixth, a cause worded without any listed word, got through. A check built from word lists has that limit, and Claude said so when it handed over the script. Someone has to read the paragraphs.
We ran all four prompts a second time in a clean folder, in one session that held all four messages. The script flagged the same seven accounts with the same figures.
It also added the party column on its own, and its review names vendors and notes that the vendor name on AP-49618 points to print work.
The review pointed to the planted entry on the same six accounts that have one, and said the file shows nothing for Insurance, with different wording, and this time the Professional fees paragraph did say that the reclass explains the drop.
The strict check from Prompt 4 could not read the second review: it expects the sentence shapes of the first one, it took an invoice number, FRT-8841, for an entry ID, and it flagged the word "reversed" in a conditional sentence. We read the second review by hand against the GL.
3. Give the controller the open items
The script cannot decide how much of a move the lines must explain, or whether to write one paragraph for two linked accounts. Your controller decides and you add it to Prompt 1.
Where ChatFin fits
The files above show what four prompts and a short test give you. What is missing is a ledger connection that pulls the detail by itself, a place where the controller edits and signs off each paragraph, and a record of who changed what.
ChatFin's own build or buy page lists the governed connection, the approval workflow and the audit trail as the parts you get when you buy (Build vs Buy: Finance AI Agents in 2026).