ALPHA WRENCH

Home / The AI Finance Lab / Lesson 1

Lesson 1 · Week 1 · Day 1

The AI Was Right. The Annual Report Was Off by 1,000.

An AI extraction of an annual report comes back as clean JSON with every field filled, and it hides eight planted defects. One of them makes a whole table a thousand times too small. This lesson splits the job so the model only reads, Python does every calculation, and scripts prove each number against the page it came from.

Lesson 1: AI financial statement extraction Watch · 11:31
Watch on YouTube ▸ Get the free workbook

The workbook has the data, prompts, scripts, five graded exercises and the answer key. Free, delivered by Gumroad.

What you'll learn

  • Why "extract the income statement and compute the margin" is really five jobs, and how each one fails quietly
  • Three contracts plus a red team: the model transcribes into a strict JSON schema, Python owns sign, scale and decimals, scripts validate
  • A verbatim check and a footing tolerance taken from printed precision, and how to prove a source error instead of quietly fixing it
  • Patching what the validator misses (scale, restated flags, column position) with a QA gate, a seeded human sample and a changelog

Chapters

  1. 0:00Hook
  2. 0:28Why standard prompting fails
  3. 1:05The pattern: 3 contracts + a red team
  4. 2:20Lab files and the source PDF
  5. 3:22Extractor prompt and JSON schema
  6. 4:20Model output and the validator
  7. 5:08Running the validator
  8. 5:44Triage: one cell per break
  9. 6:54Proving a source error
  10. 7:15What the scripts miss
  11. 7:57Patch: qa_gate.py
  12. 8:54The fix and re-validation
  13. 9:41Gate passes, human sample, changelog
  14. 10:30The full QA gate
  15. 10:47Recap 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 extraction looks perfect: clean JSON, every field filled. It's hiding eight planted defects, and one makes a whole table a thousand times too small. Today we build the checks that catch them. I'm Miguel. This is lesson one of a free, twenty-lesson masterclass, and the workbooks are free too. Week one, day one: extraction is not computation. Every number we use should have a source, and a test you can rerun.

0:28 Why standard prompting fails

Here's the prompt most teams start with: extract the income statement and compute the EBITDA margin. It looks like one task. It's actually five. One pass has to locate the table, transcribe it, fix the signs, apply the scale, and do the arithmetic. Each step can fail quietly. A bracketed negative gets read as a positive. Values slide into the restated comparatives. The scale line gets dropped. And the margin is computed on corrupted figures that still look perfectly reasonable.

Worse, models like to repair documents. They smooth over a footing difference, and that destroys the evidence that the source itself had an error.

1:05 The pattern: 3 contracts + a red team

So we split the job into three contracts, plus a red team. One: extract. The model is only a transcription engine. It copies raw strings exactly as printed, each with a page, row and column, under a strict JSON schema. Two: normalize. Python decides sign, scale and decimals, once, in tested code. Three: validate. Scripts check that every raw string is on its cited page, and that every total adds up within a rounding tolerance.

Four: red team. A fresh session hunts for the defects the scripts can't see, and each confirmed defect becomes a new rule or a new check. The payoff: every number traces back from value, to raw text, to page, row and column. Each layer has exactly one owner. Python owns computation: sign, scale, the verbatim check and footing. It never decides what rolls up into what. The model owns reading. It finds tables, reads the layout and transcribes.

It never computes, never changes a sign or a scale, and never fixes a figure. And a fresh-session auditor owns adversarial QA. It hunts errors, and never proposes corrected totals.

2:20 Lab files and the source PDF

Now let's build it, on real files. This is the day one folder from the free workbook. Data, prompts, scripts, and a key folder we won't open until the end. Everything in the data folder is synthetic example data. Nordhafen Mutual is a fictitious insurer, and no figure here is a real statistic. Here's the source: a two-page annual report extract. Page one is the income statement. Three things to notice. The scale line under the title says EUR thousands.

The comparative column says 2024 restated, with an asterisk. And there's a superscript one after net investment income for 2025. Remember that one. Page two is Note 18, the defined benefit obligation. And this note is in EUR millions, not thousands. First, I turn the PDF into page text with page markers, so the extractor can cite its pages. Same numbers, now with markers the model can point back to.

3:22 Extractor prompt and JSON schema

This is the extractor prompt, version 1.0. The role line sets the contract: transcription only, zero computation. Rule one: copy every number exactly as printed. Brackets stay brackets. Code normalizes later. Rule two: footnote markers are not part of the number. They go in their own field. Rule three: a total or a ratio that isn't printed doesn't exist. Rules four and nine anchor every cell: page, title, scale text, and the column header it's printed under.

And rules five, six and eight say: abstain, don't guess. Blanks, dashes and ambiguous roll-ups are reported, never invented. And here's the schema. Additional properties is false everywhere, and the cell status is a closed list. Look for a field called value, or total, or margin. There isn't one. The schema has no place for a computed number, so computation can't leak into extraction.

4:20 Model output and the validator

The workbook ships a simulated model output, made to look like an extractor run. It looks clean. Every cell has raw text and a status. Is it right? Reading it won't tell you. So we test it. This is the deterministic layer, and it runs in a strict order. First, the schema gate. Any schema error stops the run. Never hand-edit the JSON to make it pass. Second, normalize. Unicode minus becomes a hyphen, dashes and n/a become nothing, brackets mean negative, and it all runs in Decimal, never floats.

Third, the verbatim check: every raw string has to appear on the page it cites. Fourth, footing. The tolerance comes from printed precision: half a printed unit, times the number of components plus one.

5:08 Running the validator

Let's run it on the model output. 52 cells, two verbatim misses, six problems, and exit code one. That's expected. The file has planted defects. Now the important part: triage. For each break, find the single cell that explains it. This exact folder, with the data, scripts and answer key, is in the free workbook.

5:44 Triage: one cell per break

First verbatim miss: net investment income, 96,4801. The page says 96,480 with a superscript one. The model glued the footnote marker into the number. That's also why total income breaks by almost 870 thousand. One cell explains both. Second miss: net defined benefit liability, 31.6. The page prints 31.5. The model did its own arithmetic. Footing doesn't catch this one, because a difference of 0.1 is inside the tolerance.

The verbatim check does. Total expenses breaks in both years. In 2025, acquisition costs lost their brackets, and administrative expenses are swapped between the two columns. Both Note 18 totals break too. Count the rows: remeasurement, experience is missing. The gaps are 2.5 and 2.9, the missing row is 2.4 and 2.9, and the extra 0.1 is source rounding, inside the tolerance. And profit before tax for 2025 is off by exactly 1,000.

That's not the model. Let's prove it.

6:54 Proving a source error

Python adds the four printed expense lines straight from the page: 1,070,700. The page prints 1,069,700. The source itself is off by a thousand, and profit before tax was computed from the true total. That's a document finding. We record it. We never quietly fix it.

7:15 What the scripts miss

So the validator caught five planted defects. Three passed every check. Note 18 is labelled EUR thousands, but the page says millions. Footing doesn't care about scale, so it can never catch this, and every pension figure is now a thousand times too small. The 2024 column says restated, but the flag is false. And other income for 2024 is a dash on the page, but the model wrote zero, with status value. This is what the red-team prompt is for.

Run it in a fresh session with your own model, then turn each defect class it confirms into a check.

7:57 Patch: qa_gate.py

Here's my patch, qa_gate.py: three checks the validator lacks. I'll type the scale check live: the scale text has to be printed on the cited page. Next, a header that says restated must carry the restated flag. And the strongest one: every raw string must sit in its own column, on its own printed row. That catches sign drops, column swaps and dashes turned into zeros. At the end, every validator break must be either fixed, or logged as a document finding.

Run it on the model output. Scale, restated, and position failures, including the zero that should be a dash. Sixteen open items. The gate fails, exit code one.

8:54 The fix and re-validation

Now the fix. In production I'd rerun the extractor with the new rules. Here I apply the corrections in a script, each one traced to its page, so nothing is hand-edited. The sign, the footnote, the column swap, the dash, the restated flag, the scale, the missing row, and the printed 31.5. Validator again, on the fixed file. 53 cells, zero verbatim misses, and two problems left. Both are the source typo we just proved: total expenses and profit before tax, 2025.

And the closing obligation, 402.9 against components of 402.8, passes, because 0.1 is inside a tolerance of 0.4.

9:41 Gate passes, human sample, changelog

I logged those two breaks as document findings, with the reason. Run the gate with the findings file. Scale, restated and positions are clean, and the two source breaks are logged, not fixed. QA gate passes, exit code zero. Last, the human sample. Spot check draws a reproducible ten-cell sample with a recorded seed, and you check each one against the PDF by eye. Then one line in the changelog: planted defects caught by scripts, five of eight before, eight of eight after.

10:30 The full QA gate

Here's the full gate. Nothing ships until every row passes. Schema, verbatim, footing and the trial balances are scripted. Scale, coverage, the human sample and the red team need a human or a critic, and today we turn part of that second group into code.

10:47 Recap and next lesson

Four takeaways. The model transcribes, under a schema with no field for a computed value. Python decides sign, scale and decimals, once, in tested code. Scripts prove it, and a source error is recorded, never fixed. And a red team finds what the scripts miss. Then you patch. Your turn. The workbook has five graded exercises, including cleaning two messy trial balances. Next lesson: few-shot calibration.

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.

Get the workbook