Why Store Page Numbers and Source Text in Extracted JSON
extraction yields only one amount: 1200, the reviewer still has to reread the entire document. Saving additional page numbers and short original text fragments
Extraction that returns only a value, such as amount: 1200, leaves the reviewer rereading the whole document to check it. If you are working with extracted data from PDFs or scanned files, this guide shows how to store the page number and a short piece of the original text alongside each value, so that every figure can be traced back to its source.
Storing more location detail is usually more useful than adding decimal places to a confidence score. It lets you pinpoint errors and document every correction, and it makes review faster for anyone who checks the output later.
Note: This guide uses synthetic samples to demonstrate the method. Before processing important files, keep the original copies and check your results against the boundaries and acceptance criteria in your own project documents.
How do you keep extracted values traceable? The short answer
Save each extracted value with its page number, a short original text fragment and a file version identifier, then check that the fragment really supports the value.
| Your situation | What to do | Why |
|---|---|---|
| You extract an amount from a PDF | Store the page number and a short source fragment with the value | The reviewer can jump straight to the original text |
| Your parsing library counts pages from zero | Convert to pages starting from 1 at the boundary | The protocol stays consistent for reviewers |
| The same amount appears more than once | Do not pick the first match without checking | It may be a total, a tax amount or a prior-period balance |
| The file may be replaced or re-uploaded | Save a file content hash | It identifies the exact version the value came from |
| You proofread translations bilingually | Link each translated segment back to its source page | Reviewers verify meaning without searching the original |
Why a value alone is not enough
A bare value gives you no way to check where it came from. When a figure looks wrong, someone has to search the whole document to find it again, which is slow and error-prone.
Adding location and text evidence changes that. Each record can point back to a specific page and show the words that produced the value, so corrections are easy to explain and easy to audit.
Evidence should lead users back to the original text
Give every extracted field an evidence object that holds:
- A page number, counted from 1. If your parsing library starts from zero, convert the number at the boundary and document the conversion in your protocol.
- A short original text fragment, limited to sentences relevant to the field.
- Coordinates and their coordinate system, if you need to locate the text on the page.
Keep the fragment short. Do not copy entire sensitive pages into logs, search indexes or notification messages. A few words around the value are usually enough to verify it.
Check the shape first, then check the correspondence
A record can be structurally valid and still have no evidence behind it. Validate the structure of each record against its schema, for example using the JSON Schema object structure reference, and then check that the evidence actually supports the value.
from jsonschema import Draft202012Validator
schema = {
"type": "object", "required": ["value", "evidence"],
"additionalProperties": False,
"properties": {
"value": {"type": "string"},
"evidence": {"type": "object", "additionalProperties": False,
"required": ["page", "quote"],
"properties": {"page": {"type": "integer", "minimum": 1},
"quote": {"type": "string", "minLength": 1}}}
}
}
v = Draft202012Validator(schema)
pages = ["Invoice total: USD 1200."]
record = {"value": "1200", "evidence": {"page": 1, "quote": "USD 1200"}}
assert v.is_valid(record)
def quote_exists(r):
if not v.is_valid(r):
return False
e = r["evidence"]
return e["page"] <= len(pages) and e["quote"] in pages[e["page"] - 1]
assert quote_exists(record)
fake = {"value": "9999", "evidence": {"page": 1, "quote": "USD 9999"}}
assert v.is_valid(fake)
assert not quote_exists(fake)
assert not quote_exists({"value": "1", "evidence": {"page": 9, "quote": "x"}})
This synthetic example builds a record that is syntactically valid but has no supporting evidence. It shows that schema matching and source matching cannot replace each other.
Real PDFs can differ in word breaking, ligatures and whitespace. Substring matching is only a minimal demonstration. It is not a complete evidence-validation algorithm, so do not treat it as one.
Bind evidence to the file version
Page numbers and text fragments only make sense for one specific version of a file. If the document is replaced, the page numbers may point to the wrong content.
- Save a file content hash to identify the exact version.
- Record the page number and original text fragment for each value.
- Remember that a hash identifies the version but does not prove who uploaded the file or that they had permission to do so.
Handle repeated amounts carefully
A single document may contain the same amount several times. Before you accept a match, work out what the figure represents:
- Check the field label next to the value.
- Check the table it appears in.
- Read the surrounding context.
If you find several candidates, do not select the first one. Verify which one matches the field before you accept it.
📊 At a glance
Each saved item solves a different problem and leaves other questions open. Use this table to see what each one can and cannot guarantee.
| Saved item | What it can solve | What it cannot guarantee |
|---|---|---|
| File content hash | Identifies the corresponding version | That the uploader had file permissions |
| Page number | Narrows the search scope | That the page has not been rearranged |
| Original text fragment | Quick text verification | That the field semantics are correct |
| Coordinates and coordinate system | Positions the content on the page | That the OCR results are already accurate |
Traceability makes bilingual proofreading easier
Traceability matters most when you proofread translations. OmniDoc can be used for bilingual proofreading, so a reviewer can jump from a translated passage back to the source page and check the meaning.
The benefit is not a more complicated output. It is that each correction is clearly explained, which cuts down the time reviewers spend searching the original document again and again.
❓ FAQ
1. Why store a page number if I already have the value?
The page number tells the reviewer exactly where to look. Without it, they have to search the whole document to confirm the value.
2. Should page numbers start from 0 or 1?
Count pages from 1. If your parsing library starts from zero, convert the numbers at the boundary and record the conversion in your protocol.
3. How much of the original text should I store?
Store only short sentences that are relevant to the field. Avoid copying whole sensitive pages into logs, search indexes or notifications.
4. What if the same amount appears more than once?
Do not pick the first match. Check the field label, the table and the surrounding context to find out whether it is a total, a tax amount or a prior-period balance.
📝 Summary
A value on its own is hard to check, so store its page number, a short source fragment and a file content hash with it. Validate both the structure and the correspondence of each record before you trust it. Traceable records make corrections easier to explain and proofreading faster.
Try it now: upload a document and get it translated with the layout intact


