AI School · Level 2 · Lesson 3

Extracting data from a PDF

Léelo en español →

This is the most requested thing and the least checked: hand it a PDF — a payslip, a blood test, a delivery note, a report — and ask for the data in a table. It works, it saves a long stretch of your afternoon, and it fails in one very specific way that you need to know about before you trust it.

The model does not read the PDF the way you do. And what it does depends on a detail almost nobody checks: whether that PDF has text inside it or is a photograph of a piece of paper.

Two PDFs with the same name and nothing in common

PDF with textScan or photo
How you tellYou can select and copy a wordTrying to select gets you a rectangle
What the model readsThe characters, as they areThe image: it interprets the shapes
How it goes wrongRarely, except with multi-column tablesIt confuses similar digits and fills in the blurry parts
Does it show?UsuallyNever
A filled-in digit looks exactly like a read digit. It does not come in italics, it carries no warning, it is not smaller. If the 3 was half rubbed out and the context calls for a number, a number comes out — and on a payslip or a blood test that number is the entire point.

The three rules

1. Name the fields, one by one

"Pull out the data" lets the model decide what counts as data. "Pull out basic pay, supplements, gross total, total deductions and net pay" leaves nothing to its judgement — and if one of them is absent, you notice, because a row is missing.

2. Require "not legible" instead of a guess

This is the "what to do when it does not know" piece from lesson 1, and here it decides everything. Without it, an unreadable field comes back filled in.

3. Make the arithmetic add up against the paper

It is the cheapest check there is and the one that catches the real error, because a misread figure almost never adds up with the rest of the document:

DocumentWhat has to add up
PayslipBasic + supplements = gross · gross − deductions = net
Blood testEvery value, inside the reference range printed on the paper itself
Delivery note or invoiceUnits × price = line total · sum of lines = total
Any of themDates consistent with each other, and none in the future
Arithmetic is your checker. You do not need to re-read the whole document: if the totals add up, the individual figures were almost certainly read correctly. If they do not, you already know where to look.

A prompt that works

Here is a payslip. Extract ONLY these fields, as a table:
period · grade · basic pay · supplements (one per row)
· gross total · total deductions · net pay.

If a field cannot be read with confidence, write "not legible".
Do NOT infer it from the others and do NOT work it out yourself.

At the end, tell me whether the gross total matches the sum of the
items, and whether the net matches gross minus deductions.

That last paragraph is what turns the extraction into something checkable: you ask for the arithmetic and all you have to do is see whether it says it adds up.

And the PDF belongs to somebody

A payslip, a blood test or a report are personal data. If it is yours, it is your call. If it belongs to an employee or a patient, it is not: there you are the data controller, and uploading it to a chat is a disclosure nobody authorised. The full reasoning is in the first lesson.

For the specific case of your own payslip, this site has a tool that does exactly this and compares what it extracted against the collective agreement tables — the difference being that the document does not go into a general-purpose chat, the comparison is not improvised by a model, and a pharmacist reviews the report.

A full example, and what is wrong with it

The prompt above ends by asking it to check the sums. This example shows why that check, written the way it is, is worth nothing — and what to do instead. It is the most expensive failure in the whole lesson and you cannot see it by reading the reply.

It is given a photo of a payslip (not a text PDF: a phone photo, which is how nearly all of them arrive) together with the full prompt above.

What it replies

Period: 01/03/2026 – 31/03/2026 · Grade: Pharmacy Technician

Base salary: €1,249.00 · Supplements: €170.90 · Total gross: €1,419.90

Total deductions: €178.20 · Net pay: €1,241.70

I have checked the sums: the total gross (€1,419.90) matches the sum of the items, and the net (€1,241.70) matches gross minus deductions. Everything adds up correctly.

And now, what is wrong with that reply:

  1. The check is circular, which is why it always adds up. It added up what it read itself, not what is printed on the paper. The base salary on the original was €1,240.00 and it read €1,249.00: from there, all its numbers are consistent with each other and none of them is the payslip's. Asking it to check its own figures is asking it to correct itself with the very data it has just invented — "everything adds up" comes out no matter what. And that "everything adds up correctly" is precisely what stops anybody looking at the paper again.
  2. A smudged 4 and a 9 look alike. Nine euros a month. In a photo with a shadow, the stroke of a closed 4 is almost a 9. The model does not "hesitate": it picks the one that fits and writes it with the same poise as every other digit. It does not come out in italics, with a warning, or in smaller type. Nine euros a month is €126 a year counting the extra payments — and in a back-pay claim covering three years, it is the whole claim. On a blood test, the same error moves a value across a reference range.
  3. The supplements arrive merged into a single figure. You asked for "supplements, one per row" and it returned €170.90 in one piece. The total is the same, so the sums add up and nothing looks missing — but what has been lost is which part was the absorbable "on account of the agreement" supplement and which was seniority, which is not absorbable. Precisely the split that decides whether that payslip is right or wrong. The error is not in a number: it is in a row that does not exist.
  4. And it has not written "not legible" once. You asked for it explicitly and the photo has a shadowed corner. The "what to do when it does not know" instruction is the key piece of the whole of Level 2, and here writing it is not enough: the model does not perceive a smudged digit the way you do, because it is not looking at a doubtful image — it is producing the likeliest text given what it sees. The way to test whether the instruction works is to feed it a document with a deliberately covered patch. If it says nothing, it is not applying it.

The check that does work differs by one phrase, and it changes everything: "tell me what the TOTAL GROSS box says on the document, and compare it with the sum of the items you extracted". Now there are two separate sources — what is printed in one box and the sum of others — and a discrepancy becomes possible. With the payslip above it would have said: sum 1,419.90, box 1,410.90, does not match. And now you know a digit was misread, and where.

The general rule holds for any document: a check is only worth something if it can fail. If the answer is "it adds up" no matter what, you were not checking anything.

And if your pharmacy is not like that

If the document is a set of blood results. Here there are no totals to reconcile, so the verifier has to be something else: the sheet itself carries the reference ranges next to each value. Ask it to extract "value, unit and reference range exactly as printed" — all three, every time. A bare value cannot be checked; a value with its range can, because if the model invented the digit it will most likely land somewhere inconsistent with the rest of the profile.
If it is a wholesaler delivery note or invoice. This is the best case in the whole lesson, because the arithmetic is dense: units × price = line amount, and the sum of lines = total. With that many internal relationships, one misread digit nearly always breaks one of them. Ask it to extract the lines and compare their sum with the total printed at the foot — again, two sources. And watch the discount and the VAT, which is where these extractions get tangled more often than the figures do.
If it is a clinical report rather than a table. It changes the problem entirely: there are no figures to reconcile here, there is what got left out, and no arithmetic detects that. The method is in Level 3 and the short rule is not to ask for "a summary" but to ask field by field — diagnosis, discharge medication, changes from before, follow-up — because an empty field is visible and an incomplete summary is not. And before anything else: that document belongs to somebody (lesson 1).
If the PDF really does have text inside. Then the invented-digit risk drops a great deal and the other one remains, which is multi-column tables: a figure that jumps column changes concept without changing value, and that reconciles just as well. The check stays the same — compare against a printed box — but you can trust the rest far more. Checking whether the text can be selected before uploading takes two seconds and tells you which scenario you are in.

When it does not work first time

It tells me it adds up and I can see that it does not.
Good: you have just found the digit. Do not ask it to "review it" — it will add its own figures up again and they will reconcile again — ask it what literally appears in that specific box, one at a time. Forcing it to look at one place again instead of recomposing the whole table usually fixes the reading by itself. And if it still does not reconcile, that is the field you type in yourself.
The photo is poor but it is all I have.
Before wrestling with the prompt, fix the photo: straight on, no shadow, in pieces. Four photos of a quarter of the payslip each work far better than one of the whole sheet, because every digit occupies four times the area. And if the document is yours and you have it in your bank or payroll app, download the PDF: 80% of this lesson's problems disappear when the document has real text inside.
It extracts correctly but changes date and decimal formats.
The least dangerous failure and the most annoying, and it is fixed in the prompt: "copy the values exactly as written, without normalising dates or separators". It matters more than it seems if you are going to paste the table into a spreadsheet — 1.240,00 turned into 1240.00 or 1,240.00 stops summing, and worse, sometimes sums wrongly in silence. Same with dates: 03/04 does not mean the same thing on both sides of the Atlantic.
So do I trust the extraction or not?
You trust the extraction and you do not trust its check. Two different things, and that is the whole lesson: pulling twenty fields out of a document by hand is fifteen minutes and two typos of your own; pulling them out with AI is thirty seconds, and the check — one printed box against one sum — is another thirty. It is still the best trade in the school. What you cannot do is skip the second thirty seconds because the reply said "everything adds up".

Before you call this learned

← Previous: summarising a paper Next: patient-facing material →