How to get a confidence score for every field extracted from a PDF¶
A confidence score the model wrote about itself is a guess about a guess.
Ask an LLM to add "confidence": 0.97 next to each value and it will, for right and wrong values alike. A score
is only useful if it comes from evidence, and if someone has measured how often values with that score are right.
There are three places a per-field score can come from.
| Source of the score | What it measures | Where you get it |
|---|---|---|
| OCR engine | how sure the engine is about the characters it read | cloud OCR services: Amazon Confidence from 0 to 100 on each block, |
| The model's own number | nothing you can check | any LLM, if you ask. Do not use it to skip review |
| Evidence for the value | the value was found on the page, two reads agree, it does not conflict with another value | an extractor that returns citations |
The first kind answers "were the characters read correctly", not "is this the right field". A crisp, perfectly read number from the wrong row scores 99. The third kind is the one to route review on.
Per-field confidence with citations¶
ReadAnyDoc (open source, Apache-2.0) returns every extracted value with the text it was read from, the page and box, a confidence tier and a score:
import readanydoc
from pydantic import BaseModel
class Invoice(BaseModel):
invoice_number: str
total: float
due_date: str
out = readanydoc.extract("invoice.pdf", schema=Invoice)
for path, cites in out.citations.items():
c = cites[0]
print(path, c.confidence, c.score, c.bbox.page if c.bbox else None)
# invoice_number high 0.94 1
# total high 0.94 1
# due_date low 0.79 1
confidenceis a tier,highorlow. It comes from how the value was found: a match in the PDF's own text, agreement between independent reads, a checked total.scoreis from 0 to 1 and is measured, not felt: for the common cases it is the share of such values that were right on our benchmarks. It can beNonewhen there is nothing measured for that kind of value.- A field with no entry in
out.citationshas no source that could be located. Treat it as the lowest confidence of all.
The printed scores above are examples of the shape; your documents give their own.
Send only the doubtful fields to a person¶
def needs_review(out, fields):
"""Field paths a person should check: no source, a low tier, or a low score."""
review = []
for path in fields:
cites = out.citations.get(path) or []
if not cites:
review.append((path, "no source found"))
elif any(c.confidence == "low" for c in cites):
review.append((path, "low confidence"))
elif any(c.score is not None and c.score < 0.9 for c in cites):
review.append((path, "score below 0.9"))
return review
needs_review(out, ["invoice_number", "total", "due_date"])
# [('due_date', 'low confidence')]
Pick the threshold from your own data: label 100 documents once, then check how often each tier was right.
How much the tiers are worth¶
We measured it on 16 10-Q filings checked against their XBRL facts and 100 CUAD contracts, 2,601 values, held out by document. On the 10-Qs:
| Tier | Share of values that were right |
|---|---|
high |
94.3% |
low |
79.3% |
So low does not mean wrong. It means one in five is, which is the pile worth a person's time. These numbers are
for these document kinds, not a guarantee for yours.
Where this loses¶
- It is a two-step tier plus a measured score, not a calibrated probability for every field of every document type. Azure and Textract give a finer-grained number for the OCR step.
- It is slow: about 20 to 50 seconds a page.
Reducto takes about 4 (our run).
- On forms, Reducto finds slightly more question/answer links than ReadAnyDoc on FUNSD (78.6% against 77.4%, 199 forms, our run).
Questions¶
Can I use token log-probabilities as a confidence score? They tell you how sure the model was about the next token, which is high for fluent wrong answers too. They are a weak signal on their own; combine them with a check that the value is printed on the page.
What threshold should I use?
There is no universal one. Start by reviewing everything marked low and everything with no source, measure how
many of those were wrong, and tighten from there.
Does a high score mean I can skip validation? No. Keep the cheap checks: the number is printed on the page, and the arithmetic holds. See how to check extracted numbers.