Home / The AI Finance Lab / Lesson 2
Lesson 2 · Week 1 · Day 2
AI Called a 108,000 Revenue Shortfall 'Favourable'
Budget-versus-actual commentary from a model can read like a controller wrote it: thirteen lines, each with a driver and a citation. A script finds ten errors in it, from a favourable that is really adverse to a cause nobody gave the model. Two more wrong drivers pass every check. This lesson builds the controls that catch them, and shows how the order of the few-shot examples alone moves accuracy between 84.6% and 100%.
Watch · 8:34
The workbook has the data, prompts, scripts, five graded exercises and the answer key. Free, delivered by Gumroad.
What you'll learn
- A Python variance engine that owns arithmetic, signs and materiality (at least EUR 50,000 and at least 5%) and freezes them in a fact sheet
- A closed driver taxonomy with written boundary rules, where "insufficient evidence" is a correct answer rather than a failure
- Re-checking every prompt constraint in code: a prompt constraint is a request, a script is a control
- Measuring calibration against gold labels you write first, then shuffling the examples to count label flips
Chapters
- 0:00Hook
- 0:37The calibrated pattern
- 1:27Lab files
- 1:46The variance engine
- 2:36Materiality boundary
- 3:06The commentary prompt
- 3:45Gold labels first
- 4:03Check the model output
- 4:26Triage the breaches
- 5:16What the script can't see
- 5:37Measure calibration and order flips
- 6:10Patch: timing check
- 6:53Seed the checks
- 7:35Fix the calibration
- 7:51Recap and next lesson
Transcript
Every figure in this lesson comes from synthetic example data for a fictitious insurer, Nordhafen Mutual. No figure is a real statistic. Narration uses an AI-generated clone of the creator's own voice. Lightly edited for reading.
0:00 Hook
This variance commentary reads like a controller wrote it: thirteen lines, each with a driver and a citation. Then a script reads it. Ten errors: a favourable that's really adverse, a rounded percentage, and a cause nobody gave the model. And two wrong drivers no script can see. Today we catch all of them. I'm Miguel, and this is lesson two of a free, twenty-lesson masterclass. Week one, day two: few-shot calibration.
The model quotes the numbers. It never computes them.
0:37 The calibrated pattern
Variance commentary fails in three predictable ways. The model does the maths and gets the sign wrong on cost lines. It reaches for plausible drivers, like timing, with no evidence. And its labels drift with the order of the few-shot examples. So the job runs in four stages. One: a Python engine does all arithmetic, signs and materiality, and freezes them in a fact sheet. Two: the model classifies drivers from a closed taxonomy, with a legitimate way to say insufficient evidence.
It only quotes display strings. Three: every prompt constraint is checked again by a script. A prompt constraint is a request. A script is a control. Four: calibration is measured, against gold labels you write first, and by shuffling the examples to count label flips.
1:27 Lab files
Here's the day two folder from the free workbook: October 2026 budget versus actual, for one cost centre of Nordhafen Mutual AG. Twenty-four lines, fifteen evidence items, and a model output with planted breaches. It's all synthetic example data: no figure is a real statistic.
1:46 The variance engine
The engine is 39 lines of pandas. First, a mapping gate: an outer merge, and any line that doesn't match on both sides stops the run. Direction comes from the line type, never from the sign. A cost over budget is adverse. Revenue over budget is favourable. Materiality is an AND rule: at least EUR 50,000, and at least 5%. Run it. Control totals: actual 10,466,800, budget 10,010,000. Agree those to the ledger before anything else.
Now the dirty export. Exit code one, three unmatched lines. L33O has a letter O where a zero should be, and L999 is suspense with no budget line. The fix belongs in the mapping, with its owner. Never rename lines in the facts file to make the engine run.
2:36 Materiality boundary
The fact sheet holds display strings, a direction word and a material flag. Thirteen of twenty-four lines are material. Depreciation displays 5.0%, but it isn't material. The unrounded figure is 4.9917%. Display rounding must never drive the threshold test. And legal fees, at exactly 50,000, is material, because the test is greater than or equal.
3:06 The commentary prompt
This is the commentary prompt, version 1.0. The role line: you classify drivers. You never calculate. A closed taxonomy, with written boundary rules. Timing needs a named later period in which the amount reverses. No named period, not timing. And insufficient evidence is a correct answer, not a failure. The constraints: every number appears verbatim in the facts or in cited evidence. Copy the direction word. No banned words.
Forty-five words at most. Four calibration examples, chosen to be contrastive. This one looks like timing, but there's no reversal period, so it abstains, and says what evidence is missing.
3:45 Gold labels first
Before I look at any model output, I write my own gold labels, from the evidence and the boundary rules alone. Training was postponed with no new date, so that's insufficient evidence. Legal fees has no evidence at all: same answer. The pension budget used last year's salary scale. That's a budget error, not a rate change.
4:03 Check the model output
Now the model output. The workbook ships it as a simulated run with planted breaches. And here's the constraint checker. Thirteen lines, ten errors, exit code one. This folder, with the data, scripts and answer key, is in the free workbook.
4:26 Triage the breaches
Intercompany recharges: the facts say adverse, and the model wrote favourable. A revenue shortfall, called good news. Third-party fees: the model wrote 18%. The facts say 18.7%. A rounded number is an untraced number. Energy: 57.1% appears nowhere in the facts or the evidence. Python shows where it came from: the model divided the two tariffs itself. Legal fees: a litigation story with no evidence cited, and a banned word.
The model invented a cause. Coverage: IT consulting is missing, and permanent salaries is in, at 2.5%. And the software reclass names no offset line.
5:16 What the script can't see
The script caught ten. Two wrong drivers passed, because they're perfectly well formed. Pension cost is labelled price rate, but the evidence says the budget used the 2025 salary scale. That's a budget error. Training is labelled timing: spend expected later in the year. The evidence says: no new date set. The model invented the reversal.
5:37 Measure calibration and order flips
This is why gold labels come first. Accuracy: 69.2%, on thirteen lines. The confusion matrix shows where: budget error read as price rate, and insufficient evidence turned into one-off and timing. Now the same prompt, with the four examples in three different orders. Two lines flip: pension cost, and training. Per-run accuracy: 100%, 92.3% and 84.6%. Same evidence, same prompt. Only the example order changed. Training flips to timing in one ordering, and the checker can't see it.
6:10 Patch: timing check
So I turn the timing boundary rule into a control. For every line labelled timing, collect the text of the evidence it cites, and look for a named period: a month, a quarter or a year. No named period, it's a breach, and the script exits with code one. On the model output, training has no named period. Facilities maintenance cites January 2027, and passes. On the three orderings, it flags exactly the run where training flipped.
And on the reference commentary: zero breaches. It's a floor, not a proof. A reviewer still checks that the named month is the reversal.
6:53 Seed the checks
Now prove the controls bite. Take the reference commentary, which passes everything, and break it on purpose. First: call cloud hosting favourable. Caught: the facts say adverse, so the direction word is missing. Next: round energy from 45.3% to 45. Caught: an untraced number. The hard one: relabel training as timing. The constraint checker passes it, zero errors, because the line is perfectly well formed. The timing check doesn't: no named period, exit code one.
Three seeds, three catches. If a seed ever passes, fix the control before you trust the commentary.
7:35 Fix the calibration
For the pension flip, the answer key's fix is a fifth calibration example: a rate rise known before the budget was set is a budget error, not a price rate. Then rerun all three orders, and require zero flips on material lines before anything auto-ships.
7:51 Recap and next lesson
Here's what passing looks like: the reference commentary. Thirteen lines, zero errors, exit code zero. Recap. Python owns arithmetic, signs and materiality. The model only quotes. A closed taxonomy, with an honest way to say: we don't know yet. Every constraint is enforced twice. And calibration is measured: gold labels first, then shuffle the examples. Your turn. The workbook has five graded exercises, starting with that mapping gate.
Next lesson: chain of verification, claim by claim.
Free workbook
Run this lesson on your own machine
The same folder used in the video: data, prompts, scripts, five graded exercises and the answer key.