Metadata-Version: 2.4
Name: evidence-citations
Version: 0.9.0.post11
Summary: Deterministic verification of numerical claims against physical PDF table cells, standalone or in RAG pipelines, with rule-based plain-text checks.
Author: Türkay Kaya
License-Expression: AGPL-3.0-only
Project-URL: Repository, https://github.com/kayaturkay1-ctrl/evidence-citations
Project-URL: Public evaluation, https://doi.org/10.5281/zenodo.24731971
Project-URL: Restricted research archive, https://doi.org/10.5281/zenodo.24726819
Keywords: rag,llm,citation verification,fact verification,deterministic,pdf,tables,table verification,cell attribution
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: COMPONENTS.txt
License-File: rights/AGPL-3.0-only.txt
Requires-Dist: PyMuPDF>=1.24
Provides-Extra: pdf
Dynamic: license-file

# Evidence Citations

**Verify which cell a numerical claim cites in a PDF table.** Evidence Citations uses the positions of printed words to find the entry named by a row and heading. It runs on a CPU and compares the claimed value only after selecting the cell.

**PDF table verification is the primary focus, standalone or inside a RAG pipeline, with additional rule-based verification for plain-text answers.** One deterministic engine serves three uses, without calling another model:

- **Standalone table verification.** Check a numerical claim against the printed table cell it names, with no language model involved.
- **RAG verification.** When an LLM answer cites a PDF table, check each table number against the cited page before the answer is shown. [See the RAG table example](#rag-answers-that-cite-pdf-tables).
- **Plain-text checks, as an extra.** Rule-based checks of quotations, values, negation and wording for text sources. They have not been benchmarked, and general semantic entailment (NLI) is not supported. [See the plain-text examples](#plain-text-and-rag-answers).

The three blind panels measured cell attribution for supplied table claims, not end-to-end RAG answer quality.

**Available on [PyPI](https://pypi.org/project/evidence-citations/)** for Python 3.10 and later. One command installs the library with PDF support:

```sh
pip install evidence-citations
```

[What it verifies](#what-it-verifies) · [Verify RAG table answers](#rag-answers-that-cite-pdf-tables) · [Check plain text](#plain-text-and-rag-answers) · [Run the PDF example](#try-it-on-a-pdf) · [See the table lookup architecture](#table-lookup-architecture) · [Compare all eight methods](#eight-methods-on-the-same-claims) · [Reproduce the comparison](#reproduce-the-comparison)

![Indonesia row with two adjacent values of 158. Local lookup selected word 198 under the requested heading. The Docling grid selected word 199 in the next column.](https://raw.githubusercontent.com/kayaturkay1-ctrl/evidence-citations/3f058186a2431c371b86199ba9845896c472fbd0/docs/figures/which-158.png)

Both systems approved **158**. Both withheld approval when the claimed value was changed. Only one selected the cell marked by the independent XML reference. This recorded ICDAR development example is why the library keeps the **word IDs** behind a proposal: two identical verdicts can point a reader to two different places on a page.

## What it verifies

| Capability | Entry point | Evidence and scope |
|---|---|---|
| Attribute a numerical claim to a printed table cell | `CitationEngine(mode="strict")` | **Evaluated** on three blind panels of born-digital PDF tables. [See the eight-arm comparison](#eight-methods-on-the-same-claims). |
| Check the table numbers in an LLM answer against the cited PDF cells | `verify_answer` in `CitationEngine(mode="strict")`, with `parse_records` and a registered PDF | Uses the same table engine as the evaluation. The blind panels supplied the claims from annotations, not from model output. [See the RAG table example](#rag-answers-that-cite-pdf-tables). |
| Locate a quotation on its designated PDF page | `CitationEngine(mode="strict")` | Part of the table evaluation. Standalone quotation location has no separate benchmark here. |
| Check a claim against an authorized text passage | `CitationEngine(mode="text_only")` | Implemented. Examples below cover a changed amount, reversed negation, stronger wording and a missing quotation. Plain-text accuracy has not been benchmarked. |
| Link claims in an answer to citation records | `verify_answer` | Implemented. Returns claim verdicts and reasons. The structured citation channel works with caller-supplied model output. |
| Check explicitly annotated claims and validity dates | `verify_claims` | Implemented. The caller supplies claims, evidence links and any validity intervals or as-of date. |
| General paraphrase or semantic entailment (NLI) | — | **Unsupported.** The text verifier uses defined matching rules; it has no general-purpose model for deciding that two sentences mean the same thing. |

<a name="how-lookup-works"></a>

## Table lookup architecture

How do you find the *2012 total* when a PDF gives you words and coordinates, but no cell borders? The local verifier needs to resolve one row–column intersection. In this example from SEE’s 2012 financial statement, it uses the white space between amounts on nearby rows to establish the column.

![Table lookup architecture. Three peer rows define two horizontal spans separated by a gutter. The 2012 heading and the Total entry of $4.6 overlap the first span. PDF words 359 and 360 are selected whether the claim says $4.6 (approved) or $9.8 (withheld).](https://raw.githubusercontent.com/kayaturkay1-ctrl/evidence-citations/20f4974c8147e4bf19ff10906ff3677d6fdbe5a7/docs/figures/table-lookup-architecture.png)

1. **Find the row.** The verifier locates the row label and the quotation in the passage the caller authorized on that page. If a label repeats, the quotation can distinguish the rows. The named heading determines which column to check.
2. **Build a virtual column from the print.** For the body-gutter test, project the left and right edges of nearby body fragments onto the horizontal axis. Merge overlapping or closely spaced intervals. Here, a gap persists between the two groups of amounts across three peer rows. The green band shows the resulting horizontal span extended vertically so you can see that both *2012* and the first *Total* entry overlap it. The adjacent *2011* entry falls across the gap.
3. **Compare only after selection.** The selected entry is `$4.6`, PDF words **359 and 360**. Changing the claim to `$9.8` leaves those IDs unchanged, even though `$9.8` is printed one column over. The first claim is approved and the second is withheld.

The body-gutter test is one way to establish a column. Aligned peer entries or a heading row with distinct matches can also support lookup. Grouped headings require a check of the named heading path. If the enabled routes cannot resolve a unique entry, the local verifier abstains.

Each proposal records word IDs for the row label, heading and value, plus group headings where available. The comparison treats ordinary numerals as printed, with declared display aliases, and recognized currency amounts as exact quantities with their qualifiers.

<details>
<summary>Inside the body-gutter test: geometry, tolerances and abstention</summary>

![Measured positions for the SEE example. The nominal projection shows two ink spans with an empty strip between them; the 2012 span is supported by three peer rows.](https://raw.githubusercontent.com/kayaturkay1-ctrl/evidence-citations/3f058186a2431c371b86199ba9845896c472fbd0/docs/figures/body-gutter.png)

- The unit `h` is the median height of the row-label words. Starting at the cited entries’ baseline, the verifier collects nearby body lines. A large vertical gap (over `3.5h`) or a figure-free line with text spanning two entry centres stops the walk.
- On a retained baseline, words less than `0.57h` apart join the same run, measured from its covered right edge. The verifier projects eligible fragments onto the horizontal axis and joins intervals with a gap below `0.5h`. Eligible detached currency signs fold into an amount to their right and percent signs into an amount to their left.
- Each entry of the cited row must meet exactly one span, and different entries must meet different spans. The heading’s horizontal extent must overlap only the proposed entry’s span. For a wrapped heading, at least one of its printed lines must overlap that span. Another body line must put ink in the selected span and in at least one other span.
- To check dependence on the crop, the verifier shifts the admission edges and the value cut together by up to `h/4`. It checks the placements where a word crosses a limit, the endpoints and intervening midpoints. All placements must identify the same entry, and the best horizontal margin must reach `h/50`. If this test declines, other enabled selection routes may still supply evidence.

The figure redraws the horizontal marks from the study’s SEE 2012 example. When the body-gutter route was disabled in the development ablation, this claim lost its proposal. Across development panels, disabling it lost 39 positive approvals in 25 tables and gained one elsewhere. [Column model][model] · [Local selector][selector]

</details>

## Results and runtime

### What we tested on

Development used ICDAR 2013 tables, SciTSR, Camelot test fixtures, and separate samples from FinTabNet and PubTables-1M.

**Blind evaluation.** We froze the verifier before testing all eight methods on the same three panels. Each panel holds out a different unit from verifier development. [Sampling details and source references][evaluation]

| Panel | Source and documents | Source split | Held out from verifier development | Eligible plain positive claims |
|---|---|---|---|---:|
| P1 | PubTables-1M · scientific articles | Structure test | Articles | 244 |
| P2 | FinTabNet · financial statements | Train | Issuer families | 114 |
| P3 | PubTables-1M · scientific articles | Validation | Journals outside the identified development set | 245 |

### Eight methods on the same claims

Each panel column counts **correct claims that were both approved and traced to the reference cell**. The denominator includes every eligible plain positive claim, including abstentions.

| Method | P1 (244) | P2 (114) | P3 (245) | False approvals (1,497 controls) | Seconds/page (P1 / P2 / P3) |
|---|---:|---:|---:|---:|---|
| Local word geometry | 183 | 80 | 167 | 0 | 0.73 / 0.17 / 0.70 |
| Docling grid | 121 | 24 | 149 | 0 | 3.53 / 2.56 / 3.38 |
| Docling + local | 187 | 80 | 168 | 0 | 3.68 / 2.58 / 3.26 |
| PyMuPDF grid | 15 | 0 | 9 | 0 | 1.40 / 0.65 / 0.93 |
| PyMuPDF + local | 186 | 80 | 167 | 0 | 1.49 / 0.69 / 1.77 |
| TATR grid | 45 | 9 | 30 | 0 | 1.80 / 1.83 / 1.01 |
| TATR + local | 186 | 80 | 167 | 0 | 2.07 / 1.87 / 1.13 |
| Nearest-column baseline | 195 | 56 | 191 | 9 | 0.43 / 0.16 / 0.49 |

The false-approval column pools the separately scored, definitely false controls across panels: 718 same-row substitutions and 779 wrong-row requests. All nine false approvals by the nearest-column baseline were same-row substitutions. This distinction matters on P1 and P3, where that baseline also has the highest audited positive count. [P1 report][p1] · [P2 report][p2] · [P3 report][p3]

Times are end-to-end medians from three rounds on the study machine. Local word geometry, PyMuPDF and nearest-column lookup ran on CPU. Docling and TATR times include GPU grid production. Model initialization is excluded. [Timing data][timings]

### Primary comparison: local word geometry versus the Docling grid

![Cell-audited coverage on three holdouts. P1 local 183 of 244 versus Docling 121. P2 80 of 114 versus 24. P3 167 of 245 versus 149. The P3 interval crosses zero.](https://raw.githubusercontent.com/kayaturkay1-ctrl/evidence-citations/3f058186a2431c371b86199ba9845896c472fbd0/docs/figures/audited-coverage.png)

| Panel | Eligible claims | Local approved and audited | Docling grid approved and audited | Local minus Docling, percentage points [95% interval] |
|---|---:|---:|---:|---|
| P1 · PubTables-1M works | 244 | 183 | 121 | +25.4 [+16.9, +34.2] |
| P2 · FinTabNet issuer families | 114 | 80 | 24 | +49.1 [+36.0, +62.3] |
| P2 · same targets, all selected row words | 114 | 66 | 21 | +39.5 [+26.4, +53.1] |
| P3 · PubTables-1M journal holdout | 245 | 167 | 149 | +7.3 [−2.5, +17.0] |

The primary P2 audit can exempt designated dot leaders outside a text-tight row-label box. The sensitivity includes every selected word. On P3 the interval includes zero. [Design and panel definitions][evaluation]

### What happens when a grid proposes a cell?

A grid supplies a reconstructed table. In the **grid-only** comparison, the verifier looks up the claim in that structure. The **hybrid** tries local lookup first and can also check a grid proposal against the printed row and heading. The **Docling grid** results below refer to our verifier using Docling’s table structure; the verifier issues the claim verdict.

![One column with a reference row and a lower row. The local verifier approved the reference cell. The Docling-grid proposal pointed lower and the claim was withheld.](https://raw.githubusercontent.com/kayaturkay1-ctrl/evidence-citations/3f058186a2431c371b86199ba9845896c472fbd0/docs/figures/different-row.png)

On this correct claim from the P1 holdout, both proposals identified the right heading. The Docling-grid proposal took the row label and value from lower on the page. Its quotation could not be located for that proposal, so the verifier withheld approval. The local proposal passed all three coordinate checks and the claim was approved. Auditing proposed cells even on withheld claims makes this kind of error visible. [P1 aggregate audit][p1] · [Per-job research archive, restricted access][full]

## Try it on a PDF

After installation, download the [standalone example](https://github.com/kayaturkay1-ctrl/evidence-citations/blob/3f058186a2431c371b86199ba9845896c472fbd0/examples/verify_cell.py) as `verify_cell.py` and run `python verify_cell.py`. From a checkout, run `python examples/verify_cell.py`.

The example creates a temporary PDF, makes two claims about the yield at Site 2 and checks the same quotation for both. Expected output:

```text
20 approved
82 withheld
```

For your own document, register the file with `CitationEngine.register_pdf`, pass the authorized passage as a `Source` with its **one-based** page number, and call `verify_answer` with the statement and quotation. Read `result.citations` for the verified location and `result.claims` for support. The local table mode is intended for born-digital PDFs with extractable word positions.

## RAG answers that cite PDF tables

When an LLM answer takes a number from a PDF table, Evidence Citations can check it against the printed cell before the answer is shown. The engine runs after generation. It reads the model's answer, the model's citation records, and the passages and PDF pages your retriever authorized.

![RAG pipeline. Documents feed a retriever, and an LLM writes the answer with citation records. Evidence Citations checks each claim against the passages and PDF pages the retriever authorized, and returns claim verdicts, cited words and an audit.](https://raw.githubusercontent.com/kayaturkay1-ctrl/evidence-citations/86bc4286af613163418079c108d4ebc83facc773/docs/figures/rag-pipeline.png)

### What the engine needs

| Input | Supplied by | How |
|---|---|---|
| The original PDF | Your application | `engine.register_pdf(path, document_id="report")`, once per file. The engine reads printed word positions from it. If your retriever converts tables to Markdown, keep the file and page. |
| Each retrieved passage | Your retriever | `Source(id="report", parent_id=0, document_id="report", passage=text, segments=[Segment(text=text, page=1)])`. Pages are one-based. Give each source its own `id` and `parent_id`. |
| The answer | The model | The visible answer text, passed to `verify_answer`. |
| One citation record per claim | The model | `answer`: the claim sentence exactly as it appears in the answer. `source_id`: one of your `Source` IDs. `quote`: the **whole printed row**, copied verbatim. `page`: the one-based page; it may be omitted only when the source covers a single page. |
| The table claim | The model | `The <heading> for <row> is <value>.` or `For <row>, column <heading>, the table lists <value>.` |

Add a table rule to the instructions you already give the model, for example:

```python
from evidence_citations import generation_instructions

TABLE_RULE = ("When a number comes from a table, write that claim as "
              "'The <column heading> for <row label> is <value>.' and quote the whole printed row.")
system_prompt = generation_instructions() + "\n" + TABLE_RULE
```

### Example

[`examples/rag_table.py`](https://github.com/kayaturkay1-ctrl/evidence-citations/blob/v0.9.0.post11/examples/rag_table.py) builds a one-page report whose North row prints 158 under both 2023 and 2024. It then verifies a saved answer with one claim in each form:

```python
records = parse_records(CITATIONS_JSON)
with CitationEngine(mode="strict") as engine:
    engine.register_pdf(path, document_id="report")
    sources = [Source(id="report", parent_id=0, document_id="report", passage=passage,
                      segments=[Segment(text=passage, page=1)])]
    result = engine.verify_answer(ANSWER, sources=sources, citations=records, fallback=False)
```

```text
supports     -                       cell 158 under 2024  The 2024 for North is 158.
insufficient table_value_unverified  cell 133 under 2024  For South, column 2024, the table lists 120.
```

The engine selected the 158 printed under 2024, not the identical number under 2023. The second claim gives South's 2023 value as its 2024 value, so it is withheld. With `fallback=False`, only the records the model supplied are checked.

### What comes back

| Field | Contents |
|---|---|
| `result.claims` | One entry per claim: `verdict` (for example `supports` or `insufficient`), `reasons` and `supporting_records`. |
| `result.citations` | Accepted citations only, with the boxes of the located quotation on the page. |
| `result.audit` | Every record, accepted or not: `location_verified`, `support_verdict`, `reasons` and `accepted`. For a table claim, `support_details` gives the observed cell value and its regions on the page. |

### When a record cannot be verified

We tested each case below on the example report. The engine withholds the claim instead of guessing:

| Problem in the record | Result |
|---|---|
| `source_id` is not one of your sources | `source_not_authorized` |
| The quotation is not on the cited page, or the page is wrong | `quote_location_unresolved` |
| Only part of the row is quoted, a multi-page source has no `page`, or the claim is free prose such as “North reported 158 in 2024.” | No table cell is selected, and the claim is not approved. |
| The selected cell prints a different number | `table_value_unverified` |

One case is not an error to the engine. If the model names another row or heading that also exists on the page, the engine checks that cell. It verifies the claim as written, not what the model meant.

The blind panels supplied the claims from annotations. They measure cell attribution, not how reliably a model writes the claims.

## One citation, two decisions

![A claim asserting €500 is linked to a citation record whose quotation says €350. The quotation is located on page 1, but the claim receives insufficient support.](https://raw.githubusercontent.com/kayaturkay1-ctrl/evidence-citations/62739bee9a266ea8af1f8a463c85b0cdad3ec19a/docs/figures/claim-link.png)

The model supplies the answer span, quotation and source ID. The host supplies the authorized passage, page and PDF. In this example the engine locates “The deposit is €350.” on page 1. The claim says €500. The audit records `location_verified: true`, `support_verdict: "insufficient"`, `reasons: ["value_or_condition_conflict"]` and `accepted: false`. Read `result.audit` to see both decisions, including unsuccessful links. Here `result.citations` is empty.

## Plain text and RAG answers

No PDF is needed when the source is text. [`examples/verify_text.py`](https://github.com/kayaturkay1-ctrl/evidence-citations/blob/v0.9.0.post9/examples/verify_text.py) checks six citations against one synthetic annual-report passage:

```text
supported -                              Revenue reached $10 million in 2024.
withheld  value_or_condition_conflict    Revenue reached $20 million in 2024.
withheld  value_or_condition_conflict    Operating costs increased in 2024.
withheld  deterministic_support_missing  Revenue will increase next year.
withheld  deterministic_support_missing  The company purchased a French business.
withheld  quote_not_in_parent            Revenue reached $10 million in 2024.
```

The last line uses the same claim as the first, but the submitted quotation says *2025* and is absent from the source. In the other withheld cases, the quote is present: the amount changes, “did not increase” becomes “increased”, “may” becomes “will”, or the wording falls outside the supported rules.

The RAG flow is the one shown in [RAG answers that cite PDF tables](#rag-answers-that-cite-pdf-tables); a text source needs no PDF. The excerpt below checks a text source.

In a RAG application, keep the retriever’s authorized passages separate from the model’s answer and citation records. The following excerpt uses the inputs defined in [`examples/rag_answer.py`](https://github.com/kayaturkay1-ctrl/evidence-citations/blob/v0.9.0.post9/examples/rag_answer.py). Add `generation_instructions()` to your model prompt; the example supplies a saved response so you can run it offline.

```python
from evidence_citations import CitationEngine, parse_records

records = parse_records(CITATIONS_JSON)
with CitationEngine(mode="text_only") as engine:
    result = engine.verify_answer(ANSWER, sources=SOURCES, citations=records, fallback=False)

for claim in result.claims:
    print(claim["claim_id"], claim["verdict"], ", ".join(claim["reasons"]) or "-")
```

```text
claim-0-36 supports -
claim-37-71 insufficient value_or_condition_conflict
```

The two claim IDs identify character spans in the answer. Only the sources the host passes to the engine can authorize evidence. The [post9 release](https://github.com/kayaturkay1-ctrl/evidence-citations/releases/tag/v0.9.0.post9) includes both text examples; the pinned post8 links below reproduce the earlier table release.

## Reproduce the comparison

```sh
python -B evaluation/tools/table1.py
```

Run this from the repository root. It reads the [paired outcomes by cluster][clusters], recomputes Table 1 and its cluster-bootstrap intervals, and checks them against the archived scores. It runs offline with the Python standard library. The [open Zenodo deposit][public] contains the statistical inputs, scorer and timing results. Repeating the word-level audit requires the [restricted manifests and per-job records][full]; rerunning extraction also requires the upstream PDFs.

<details>
<summary>Existing tests and what each checks</summary>

- The [source fixtures][fixture] build PDFs with a wrong-column value, a quote on another page, truncated evidence and identical row text in two different tables.
- The [comparator oracle][oracle] checks cases such as `1 mg` versus `1 Mg` and `12` versus `1²`. The study wheel passed strict verdict checking on 867 must-support, 954 must-not-support and 14 either-verdict pairs.
- The [scorer self-test][scorer] checks job completeness, control denominators and whether selected headings belong to the designated table.

To invoke the original checks, download the wheel from the [release][release] into the checkout after installing the library:

```sh
python -B tests/test_parent_fixtures.py evidence_citations-0.9.0.post8-py3-none-any.whl
python -B evaluation/tools/test_comparison_oracle.py --strict-verdicts --source evidence_citations-0.9.0.post8-py3-none-any.whl
python -B evaluation/tools/score_v090.py selftest
```

</details>

## Citation and licensing

This repository accompanies *Physical Cell Attribution for Numerical Claim Verification in PDF Tables*. For the library, cite [Evidence Citations 0.9.0.post8][release] ([citation metadata][cite]). For the scoring tools and study results, cite [Zenodo · 10.5281/zenodo.24731971][public].

The 52 Python implementation modules in the public wheel are byte-identical to those in the study engine `0.9.0`. The packaging differs. The study used Python 3.12.10 and PyMuPDF 1.26.6. The SHA-256 digest of the study wheel is `7d02bbe6ac83f2b07458b2d5b3f994089c41c6317a1f9d6b3ce393125d5b64f7`.

The engine is licensed under **AGPL-3.0-only**, the evaluation tools under **Apache-2.0**, and the author’s shareable study data under **CDLA-Permissive-2.0**. Upstream material retains its own terms. [Component notice][components] · [Evaluation licences][licenses]

[public]: https://doi.org/10.5281/zenodo.24731971
[full]: https://doi.org/10.5281/zenodo.24726819
[release]: https://github.com/kayaturkay1-ctrl/evidence-citations/releases/tag/v0.9.0.post8
[cite]: https://github.com/kayaturkay1-ctrl/evidence-citations/blob/v0.9.0.post8/CITATION.cff
[evaluation]: https://github.com/kayaturkay1-ctrl/evidence-citations/blob/v0.9.0.post8/evaluation/README.md
[clusters]: https://github.com/kayaturkay1-ctrl/evidence-citations/blob/v0.9.0.post8/evaluation/results/cluster_counts.csv
[fixture]: https://github.com/kayaturkay1-ctrl/evidence-citations/blob/v0.9.0.post8/tests/test_parent_fixtures.py
[oracle]: https://github.com/kayaturkay1-ctrl/evidence-citations/blob/v0.9.0.post8/evaluation/tools/test_comparison_oracle.py
[scorer]: https://github.com/kayaturkay1-ctrl/evidence-citations/blob/v0.9.0.post8/evaluation/tools/score_v090.py
[p1]: https://github.com/kayaturkay1-ctrl/evidence-citations/blob/v0.9.0.post8/evaluation/results/P1.json
[p2]: https://github.com/kayaturkay1-ctrl/evidence-citations/blob/v0.9.0.post8/evaluation/results/P2.json
[p3]: https://github.com/kayaturkay1-ctrl/evidence-citations/blob/v0.9.0.post8/evaluation/results/P3.json
[timings]: https://github.com/kayaturkay1-ctrl/evidence-citations/blob/v0.9.0.post8/evaluation/results/timing.json
[model]: https://github.com/kayaturkay1-ctrl/evidence-citations/blob/v0.9.0.post8/source/evidence_citations/_column_model.py
[selector]: https://github.com/kayaturkay1-ctrl/evidence-citations/blob/v0.9.0.post8/source/evidence_citations/_row_projection.py
[components]: https://github.com/kayaturkay1-ctrl/evidence-citations/blob/v0.9.0.post8/COMPONENTS.txt
[licenses]: https://github.com/kayaturkay1-ctrl/evidence-citations/blob/v0.9.0.post8/evaluation/LICENSE.md
