Metadata-Version: 2.5
Name: fieldproof
Version: 0.3.0
Summary: Document extraction that shows its work: every field linked to the exact words it came from.
Project-URL: Homepage, https://antonsoo.github.io/fieldproof/
Project-URL: Repository, https://github.com/antonsoo/fieldproof
Project-URL: Issues, https://github.com/antonsoo/fieldproof/issues
Author-email: Anthony Mercer <anthony@praviel.com>
License: MIT
License-File: LICENSE
Keywords: document-ai,extraction,grounding,invoice-processing,llm,ocr,pdf,structured-output
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Text Processing :: Linguistic
Requires-Python: >=3.11
Requires-Dist: anthropic>=0.77
Requires-Dist: click>=8.3.3
Requires-Dist: fastapi>=0.133
Requires-Dist: pdfminer-six>=20251230
Requires-Dist: pdfplumber>=0.11.9
Requires-Dist: pydantic>=2.12
Requires-Dist: pypdfium2>=5.0
Requires-Dist: python-multipart>=0.0.31
Requires-Dist: rapidfuzz>=3.9
Requires-Dist: starlette>=1.3.1
Requires-Dist: typer>=0.16
Requires-Dist: uvicorn[standard]>=0.30
Provides-Extra: dev
Requires-Dist: httpx>=0.27; extra == 'dev'
Requires-Dist: mypy>=1.11; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=9.0.3; extra == 'dev'
Requires-Dist: reportlab>=4.2; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Provides-Extra: ocr
Requires-Dist: pillow>=12.3; extra == 'ocr'
Requires-Dist: pytesseract>=0.3.10; extra == 'ocr'
Description-Content-Type: text/markdown

# fieldproof

**Review extracted document fields against the words and locations that support them.**

[![PyPI](https://img.shields.io/pypi/v/fieldproof)](https://pypi.org/project/fieldproof/)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/antonsoo/fieldproof/blob/main/LICENSE)
[![Live demo](https://img.shields.io/badge/demo-antonsoo.github.io%2Ffieldproof-14524c)](https://antonsoo.github.io/fieldproof/)

An invoice extractor can quote the right words and still return the wrong total,
borrow another item's quantity, or cite text hidden beneath the visible page.
Fieldproof keeps each value with its evidence, locates the quoted words, checks
the value and related fields, and opens the remaining questions for review.
Human corrections retain the original extraction and automated verdict.

![Reviewing a hallucinated PO number and an inconsistent invoice total](https://raw.githubusercontent.com/antonsoo/fieldproof/main/docs/assets/hero-review.png)

## Try the review workflow

The **[live demo](https://antonsoo.github.io/fieldproof/)** contains five authored
document controls with deliberate review cases and a credited CORD receipt
photograph with authored extraction claims. Choose
[Arithmetic](https://antonsoo.github.io/fieldproof/#line-arithmetic) to inspect
`3 x 19.95` against a printed `39.90`, or
[Hidden text](https://antonsoo.github.io/fieldproof/#hidden-text) to compare an
image printing `$90.00` with a native text layer claiming `$900.00`.
[Scanned CORD receipt](https://antonsoo.github.io/fieldproof/#cord-ocr) shows
local Tesseract output on a real receipt whose header was already redacted.
The empty merchant and date claims stay unsupported.

Inspect a field, approve, edit or reject it, then download JSON, CSV or XLSX.
The demo uses precomputed Python reports and page images. It does not upload
or process your documents. Decisions persist in browser storage when available;
otherwise they remain in the tab. Phone layouts separate Fields and Document
views, and the loaded review works offline.

## Quickstart

This repository contains verification corrections beyond **PyPI 0.2.7**. To
process a PDF with the current source and its local review UI, install
[uv](https://docs.astral.sh/uv/) and Node 24 or later, then:

```bash
git clone --depth 1 https://github.com/antonsoo/fieldproof && cd fieldproof
uv sync --locked
uv run python scripts/bundle_ui.py && uv run fieldproof serve
```

Open `http://127.0.0.1:8000`. Upload `examples/invoice.pdf`, choose **Fixture**,
and supply `examples/fixtures/invoice.json`. This replays an extraction without
an API key. The fixture path and review UI run locally. Choosing the Anthropic
provider sends document content to that provider; the review UI itself makes
no off-origin requests.

For the current CLI/library source, including replacement of an existing
0.2.7 installation, use the pinned source:

```bash
python -m pip install --force-reinstall "fieldproof @ git+https://github.com/antonsoo/fieldproof.git@24ad5c3502b9c6bbcfe63ac55034690fa5712bfc"
```

A direct Git install has **no bundled UI**. The checkout command above builds
it. `pip install fieldproof` installs the older registry verifier with its
bundled UI; neither a matching version number nor a deployed static demo
establishes that the native source correction is installed.
[Actual public upgrade and installed-file comparison](https://github.com/antonsoo/fieldproof/blob/main/studies/form-appearances/results/public-install.json).

From the checkout, reproduce the sample through the CLI:

```bash
uv run fieldproof extract examples/invoice.pdf --schema invoice --provider fixture \
  --fixture examples/fixtures/invoice.json --out result.json
uv run fieldproof verify result.json examples/invoice.pdf
```

## Review a scanned PDF locally

Install Tesseract and its English language data on the machine running the
server, then enable the Python extra with `uv sync --locked --extra ocr`.
Build the UI and start the server as in Quickstart. Before uploading, choose
**Text source**:

| Choice | Evidence used | Page limit |
| --- | --- | --- |
| Native PDF text | Existing native words; no OCR | 64 |
| OCR scanned pages | Native words on text pages; OCR on pages without native words | 8 |
| OCR every page | OCR of rendered pages, replacing native word evidence | 8 |

For a no-key example, upload
[`cord-test-0000.pdf`](https://github.com/antonsoo/fieldproof/blob/main/examples/recorded/cord/cord-test-0000.pdf), choose OCR
scanned pages and the receipt schema, then load its
[`fixture.json`](https://github.com/antonsoo/fieldproof/blob/main/examples/recorded/cord/fixture.json). The photograph is from
NAVER CLOVA's CORD dataset, CC BY 4.0; the wrapper preserves every RGB pixel.
The extraction claims are authored, and this example measures no model accuracy.

The review identifies each page's word source and the recognizer version.
**Verified on an OCR page means supported by recognized text**; compare the
page image for recognition errors. Missing-page OCR keeps an existing text
layer, even if that layer is incomplete or wrong. All-page OCR can read visible
saved form values, and can misread text that native extraction read correctly.

OCR exports add `text_mode` and `text_source` to JSON, CSV and XLSX, while keeping
original values, automated verdicts and human corrections. A review archive
remembers the source choice and reruns OCR on restore; the restoring machine
also needs the OCR tools. Native exports and version-1 archives retain their
existing format. See the [real receipt, mixed-page and saved-form replay](https://github.com/antonsoo/fieldproof/blob/main/studies/server-ocr/README.md)
and [clean installed-package evidence](https://github.com/antonsoo/fieldproof/blob/main/docs/verification-server-ocr-2026-10-20.md).

## What a verdict means

| Automated verdict | Meaning |
| --- | --- |
| `verified` | Located evidence passed the configured support and cross-field checks. |
| `needs_review` | Located evidence is weak, ambiguous, incompatible with the value, or fails another check. |
| `unsupported` | No usable evidence quote was located for the claim. |

These verdicts describe the verifier's evidence, not the truth of a document or
the accuracy of an extraction model. Human decisions are separate: approving
or editing a value does not rerun its original automated checks.

Reviewed-only export includes approved and edited fields. **All except rejected**
also includes pending fields. Both omit rejected values and retain each exported
field's original value, correction provenance and verification status. **Save
archive** retains the PDF, original claims and all saved decisions so work can
resume after a server restart. Archives are explicit, unencrypted saves;
in-memory sessions alone are not durable.

See [review decisions, spreadsheet types and archive recovery](https://github.com/antonsoo/fieldproof/blob/main/docs/usage.md#review-decisions-and-exports).

## What gets checked

- **Quotes and values.** Whole-word alignment, repeated-quote ambiguity, printed
  signs and units, numeric precision, calendar-valid dates and document-wide
  formatting conventions. Conflicting JSON members or discarded claim fields
  are input errors.
- **Related fields.** Line-item quantities and prices, subtotal/tax/total
  arithmetic, date ordering, row association and narrowly supported labelled
  table-column contradictions. Unavailable checks stay distinct from passing
  ones.
- **Native PDF evidence.** Invisible and transparent text, outer clipping bounds
  and a bounded raster comparison. Another glyph's overlapping ink cannot by
  itself certify a covered character. Failed native associations remain
  unavailable.
- **Review provenance.** Source locations remain inspectable after corrections,
  exports and archive restoration. Bounded processing workers preserve existing
  sessions when new work cannot be accepted.

Built-in schemas cover invoices, receipts and contract terms. Providers include
Anthropic and stored fixtures. Optional Tesseract OCR is available to the CLI, library and current local
review server. The hosted demo uses precomputed reports; processing your own
PDF requires the local server.

### Bring your own schema

Use Pydantic fields of `Evidenced[T]` and the same verifier. Optional row and
column rules state relationships the schema expects. See the
[custom-schema example](https://github.com/antonsoo/fieldproof/blob/main/docs/usage.md#bring-your-own-schema),
[library example](https://github.com/antonsoo/fieldproof/blob/main/docs/usage.md#as-a-library) and
[extractor protocol](https://github.com/antonsoo/fieldproof/blob/main/docs/usage.md#bring-your-own-extractor).

## Evidence and remaining costs

The [CORD/SROIE study](https://github.com/antonsoo/fieldproof/blob/main/studies/cord-grounding/README.md) uses 1,052 real receipts
with supplied OCR and field ground truth. It measures grounding and deliberately
mutated claims, without calling a model. Stricter matching rejects all 2,251
one-letter name mutations in that retained study, while also sending
OCR-repaired names to review. These receipts informed the rules, so the result
is not an out-of-sample extraction benchmark.

The [native glyph-bounds study](https://github.com/antonsoo/fieldproof/blob/main/studies/native-glyph-bounds/README.md) retains an
actual false verification: an italic seven lends ink outside its advance box
to a covered nine in `$900.00`. All 25 authored covered controls now require
review, supported by 72 independent PDFium/Poppler omission comparisons.
Nine visible controls verify; two conservatively require review. Existing
visible stroked claims can also require additional reviews. These synthetic
controls do not measure production prevalence.

The [evidence guide](https://github.com/antonsoo/fieldproof/blob/main/docs/evidence-guide.md) maps individual claims to retained
inputs, before/after reports, independent controls and installed/browser
receipts. Each study identifies its source and publication boundaries.

The [Arabic-number correction](https://github.com/antonsoo/fieldproof/blob/main/studies/arabic-numbers/README.md) addresses
another false verification: a printed `١٬٢٣٤٫٥٦` supported a claim of `234`.
Complete amounts now retain their separators, and percentage signs cannot
disappear into plain amounts. The study includes native locale formatting and
the actual PDF review workflow.

The [spacing correction](https://github.com/antonsoo/fieldproof/blob/main/studies/spaced-numbers/README.md) prevents `1 234,56`
from verifying its tail as 234.56. It preserves uncertain grouped values for
review and uses layout to retain clearly separated quantity/price cells.
The unchanged receipt replay exposed three fragment approvals on an actual
receipt as well as the cost of additional reviews. [Verification and costs](https://github.com/antonsoo/fieldproof/blob/main/studies/spaced-numbers/verification.md).
Both corrections are included in the pinned source install above. They are
separate from the older registry verifier and hosted static demo.

The pinned source also keeps slash fractions such as `1⁄2` and `1 / 2`
whole. A native PDF previously verified 1 and 2 as that quantity; both now
require review. Fraction arithmetic remains outside the verifier. A human
correction to 0.5 retains the original claim and automated status in exports
and review archives. [Native inputs and existing-receipt replay](https://github.com/antonsoo/fieldproof/blob/main/studies/fraction-evidence/README.md).

## How it works

```text
PDF -> words + locations -> extracted values + quotes -> grounding + checks
                                                          |
                                              original report + human review
                                                          |
                                               value exports / review archive
```

The loader retains source text and geometry. Grounding associates quotes with
candidate words; verification compares the claimed values with the evidence
and applicable relationships. The UI renders the original page with highlights
and keeps corrections separate. See [design and architecture](https://github.com/antonsoo/fieldproof/blob/main/docs/design.md).

## Accuracy and limitations

The current source includes saved AcroForm appearances in review PNGs, native
paint checks and local OCR input. Filled fields previously appeared blank;
[native producer inputs and before/after controls](https://github.com/antonsoo/fieldproof/blob/main/studies/form-appearances/README.md)
retain the reproduction. This rendering correction is unreleased. Native text
extraction still excludes widget values. The CLI's explicit `--ocr-all-pages`
choice recognizes rendered form values on pages that also have native text;
it replaces native words and records OCR provenance. This checks recognized
text, with its possible errors. [Actual Tesseract and CLI replay](https://github.com/antonsoo/fieldproof/blob/main/studies/visible-form-ocr/README.md).
XFA forms are unsupported.
[Installed package and real browser/archive verification](https://github.com/antonsoo/fieldproof/blob/main/docs/verification-form-appearances-2026-10-19.md)
check the pinned source above; the static demos remain separate.

A positive raster difference does not prove readability, font-to-Unicode
correctness or exact ownership of overlapping ink. Stroke bounds can be
conservative. Native attribution requires PDFium 5.0 or later and has explicit
work budgets; incomplete observations require review. Caller-supplied and
recognized OCR text have different provenance and do not receive this native
paint audit.

OCR mistakes, wrapped or skewed tables, unclear number/date conventions and
legitimate discounts can all need human interpretation. Nothing checks that a
document is authentic. A saved correction is a decision, not newly verified
evidence. See the [full limitations](https://github.com/antonsoo/fieldproof/blob/main/docs/design.md#accuracy-and-limitations)
and [document/session limits](https://github.com/antonsoo/fieldproof/blob/main/docs/usage.md#document-sessions-and-limits).

## Development

[Development and packaging](https://github.com/antonsoo/fieldproof/blob/main/docs/development.md) covers Python/web checks,
production browser workflows, UI bundling and static-demo regeneration. The
tests use stored fixtures and local API servers; no live model call is needed.

## Contributing

See [CONTRIBUTING.md](https://github.com/antonsoo/fieldproof/blob/main/CONTRIBUTING.md). Issues and pull requests welcome.

## License

[MIT](https://github.com/antonsoo/fieldproof/blob/main/LICENSE), Copyright (c) 2026 Anthony Mercer.
