Metadata-Version: 2.5
Name: docfieldbench
Version: 0.1.0a1
Summary: An open benchmark for structured extraction from documents: wrong values, invented values, and what a pipeline can trust.
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Requires-Dist: httpx>=0.27
Requires-Dist: jsonschema>=4.21
Requires-Dist: numpy>=1.24
Requires-Dist: scipy>=1.10
Provides-Extra: build
Requires-Dist: pillow>=10.0; extra == 'build'
Requires-Dist: pyarrow>=14; extra == 'build'
Requires-Dist: pypdfium2>=4.30; extra == 'build'
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Description-Content-Type: text/markdown

# DocFieldBench

An open benchmark for structured extraction from documents. It measures what costs money in a document pipeline:
values that are wrong or invented, fields that should have stayed empty, responses that break the schema, and how
long it all takes. Run it on the included documents, or on your own.

> **Status: pre-release (0.1.0a1).** The package holds the scoring core, so you can score your own documents today.
> The dataset (v1.0.0) is being built. Nothing here is a result yet.

## What it measures
Every task is a document (PDF, image or HTML, up to 10 pages) with a JSON schema and a gold answer for every field.
Systems get the original file: reading it, through a text layer, OCR or vision, is part of the test. DocFieldBench
scores each field deterministically, with no LLM judge:

- **Precision:** of the values a system returns, how many are right. One minus precision is the *silent error rate*:
  wrong, swapped or invented values that a pipeline would store without noticing.
- **Recall:** of the values a document contains, how many come back right.
- **Abstention:** of the fields a document does *not* contain, how many come back empty. About one field in eight is
  absent by design, verified against the document.
- **Swaps:** a value that belongs to another field of the same document (the buyer's name as the seller's).
- **Conformance:** first responses that parse and match the schema. Retries are recorded, never scored.
- **Latency and cost**, measured the same way for every system.
- Optional: if a system returns a confidence per field, how much can be auto-accepted at a target error rate.

Results come per track, per document condition (born-digital, scan, photo) and per field tag (look-alike values,
line items, values that need normalising), with 95% confidence intervals from a document bootstrap.

## Tracks
| track | what | gold from |
|---|---|---|
| Business | invoices, credit notes, receipts, statements, delivery notes | embedded e-invoice XML, hand labels, rendering records |
| Records | filings, patents, rules, court opinions | the documents' own markup and official metadata |
| Forms | government forms | programmatic form fills |

No gold value comes from a model.

## Quickstart (pre-release)
```bash
pip install --pre docfieldbench
docfieldbench validate my_tasks/                          # check your task files (schema and gold)
docfieldbench score my_tasks/ predictions.jsonl --summary summary.json
docfieldbench baseline my_tasks/ --out all_null.jsonl     # the all-null baseline, for comparison
```
- **Tasks:** one JSON file per document, with its schema and a gold record per field. `GOLD_GUIDE.md` describes the
  format and the labelling rules.
- **Predictions:** one JSON object per line, either `{"task_id": ..., "raw": "<the system's reply>"}` (parsed the way
  `json.loads` would see it) or `{"task_id": ..., "parse_status": "ok", "parsed": {...}}`. A task without a line
  counts as a failed response.

Coming with v1.0.0: `docfieldbench data download`, a `run` command with adapters for common APIs and local models, and
`report`.

## Licenses
Code: Apache-2.0. Schemas and gold: CC BY 4.0. Every document keeps its own license, listed per document in the
release manifest and summarised in `DATA_LICENSES.md`.

## Training-data canary
Every data file carries the string in `docfieldbench/__init__.py` (`CANARY`). Please filter it out of training
corpora.
