Skip to main content
Back to Showcase

TraceCell: Turning OCR Output into a Sign-off-Ready Verification Ledger

Author:logicore-codeModel:MiniCPM-OCR 1.0、MiniCPM-OCR Jev、MiniCPM-V 4.7

Traces OCR output cell by cell into a sign-off-ready ledger

Someone hands you OCR output; TraceCell hands you a conclusion you can sign off on.

Document recognition models have improved fast. What really hurts enterprises now is no longer "can it read this" but "where is it wrong, and who is responsible". If one digit of an invoice amount is misread and nobody flags it, the error flows into the ledger, the reports and the reconciliation, and may only surface months later.

MiniCPM-OCR Jev gives each region a 0–1 correctness score. But between "is this region read correctly" and "can this document be signed off", there is a missing decision layer: how a score becomes "auto-pass or human review", who fixes low-scoring regions, how thresholds are set, and who notices when several documents disagree. TraceCell fills that layer.

TraceCell evidence ledger workbench

Note

The recognition, scoring and verification numbers below come from the author's own sample set (5 script-generated documents, 78 labelled items) and have not been independently verified. They do not represent real business distributions; thresholds need to be recalibrated on your own data.

One Engine, Five Scenarios​

Invoice checks, financial statement checks and contract amount checks all follow the same flow: read fields → judge how trustworthy each field is → find contradictions → decide what needs a human. So there is one engine, and all scenario differences live in a single config file, src/tracecell/scenarios.py.

ScenarioDeclared fieldsInternal checksCross-checked against
VAT invoice9Total incl. tax = amount + taxPurchase contract, service contract, statement
Technical service contract8Amount in Chinese words = amount in figuresInvoice
Expense report6Sum of items = total—
Balance sheet10Assets = current + non-current; assets = liabilities + equityInvoice (revenue)
Equipment purchase contract13Per line amount = qty × unit price; totals; words vs figuresInvoice

Field names often differ across documents — a contract says "contract total", an invoice says "total incl. tax". TraceCell declares these pairings explicitly:

Python
CrossRule("purchase_contract", "合同总价", "invoice", "价税合计", "money"),
CrossRule("contract", "乙方", "invoice", "销售方名称", "entity"),

What It Looks Like​

Feed in a document and you get a ledger. Every row can be expanded to show its location on the original image, the candidates from two recognition passes with their Jev scores, and the agent's reasoning.

Field evidence trace

The "cross-document reconciliation" view compares the five samples side by side and marks the lower-confidence side as "more suspicious":

Cross-document reconciliation

Every issue can be reviewed directly — confirmed, misread, or illegible. Reviews flow back into the ledger and also become calibration samples.

Quick Start​

No GPU needed; sample data is pre-recorded:

Bash
git clone https://github.com/logicore-code/TraceCell.git
cd TraceCell
pip install -e ".[web]"

tracecell demo # run the full pipeline on the CLI
tracecell serve # open http://127.0.0.1:8000
tracecell serve --provider minicpm # use real models

Replay mode runs the same policy code, with the three model calls replaced by recorded data.

Core Mechanisms​

Evidence ledger: the output is a table with coordinates, confidence and status, not a blob of Markdown. A field that cannot be anchored back to a source region is marked "unsupported by evidence".

Pessimistic confidence inheritance: a field's confidence is the minimum over all regions supporting it, not the average. Averaging looks "more accurate" but lets errors slip through quietly.

Adversarial verification loop: Jev can only say "this is probably wrong"; fixing it is the system's job:

Plain Text
First parse (4x) → Jev 0.31 → re-parse at 16x → best-of by Jev 0.88 → pass
↓
still failing → targeted MiniCPM-V 4.7 review
↓
still failing → human review (with crop and all candidates)

Reading the same region at 4x and 16x visual-token compression and getting different results is itself a signal of ambiguity. The escalation asks narrow questions ("is this A or B?"), so the answer is short and decidable, and can be fed back into Jev for rescoring.

Per-region budget decisions: every region gets a cost-benefit check — how much risk remains, how much another pass would reduce it, what inference costs, and what a human look costs. Critical fields get 45% of the budget, low-risk fields 5%; human review is part of the comparison and is chosen when it is more efficient.

Risk-weighted routing: documents are routed to auto-pass, spot check or full review, with the spot-check sample size computed from m ≥ ln(δ) / ln(1 - p).

Consistency checks: line items should sum to the total, quantity times unit price should equal the amount. OCR models cannot solve these contradictions, because every number was read correctly — the document itself is wrong:

Plain Text
Travel 1,480.00
Office supplies 386.50
Entertainment 1,098.00
Sum of items 2,964.50 ← the three lines added up
Printed total ¥2,864.50 ← what the form says diff +100.00

Output from Real Models​

All recorded data in the repo comes from official GGUF weights (Q4_K_M) running on llama.cpp on CPU only: samples/real_ocr/ holds MiniCPM-OCR 1.0 output, samples/jev_scores.json holds Jev scores, and samples/vlm_review/ holds MiniCPM-V 4.7 (1B) reviews of six hard regions.

V 4.7 got four of six right and two wrong — and Jev rescored both wrong answers at close to 0, so they were rejected and sent to humans instead of polluting the ledger:

RegionV 4.7 answerJev rescorePrevious bestResult
Invoice seller name南京海川软件股份有限公司 ✓0.99810.9980Adopted
Invoice total incl. tax¥145,318.00 ✓0.99350.9930Adopted
Contract amount in words伍拾捌万元整 ✓0.99360.9930Adopted
Purchase contract total in words壹拾柒万柒仟零柒拾壹元整 ✓0.98400.9855Kept previous
Expense report claimant李思源 ✗0.11830.9841To human
Balance sheet total equity¥14,100,900.00 ✗0.00000.9662To human

The runs also surfaced three kinds of problems that show why this layer matters: the title "Zhejiang VAT invoice" was read as "Jiangxi"; a contract body was replaced by a fluent, professional-sounding hallucinated paragraph unrelated to the original; and an expense report's items and total differed by 100 yuan, which only a sum check could catch since both were read correctly.

Numbers​

On the 5 samples, tracecell baseline compares three approaches:

Plain Text
Approach Human review Share Missed OCR errors Missed doc contradictions
Full manual 83 100.0% 0 0
Trust OCR 0 0.0% 2 8
TraceCell 16 19.3% 0 0

All 8 document contradictions missed by "trust OCR" were read correctly; a stronger model would not help — only cross-field checks do. TraceCell cuts 83 regions down to 16, chosen by risk: critical fields, conflicting candidates, and failed arithmetic.

Threshold calibration on 78 labelled items gives AUROC 0.9976 and an 80.77% auto-pass rate. The author stresses that the samples are synthetic and small, so this does not reflect real business data; Jev's official AUROC on other OCR outputs is 91.9–93.4.

Deployment and Integration​

ModeHardwareCapability
Fully offline, single GPU1×24GB, V 4.7 1BParse + score + escalation
Fully offline, single GPU1×48GB, V 4.7 35B-A3B AWQSame, better on hard regions
On-device CPULaptop, CPU onlyParse + score (GGUF)
ReplayNo GPUFull pipeline

Integration options: an MCP server (tracecell mcp, 9 tools), an agent skill, OpenAI-compatible APIs, and a pluggable provider protocol. Each model can also be used on its own:

Bash
tracecell case ocr invoice.png # MiniCPM-OCR 1.0 only: parsing with coordinates
tracecell case jev invoice.png # MiniCPM-OCR Jev only: QA for OCR output
tracecell case vlm invoice.png # MiniCPM-V 4.7 only: visual QA and grounding

Known Limits​

  • The default layout splitter is projection-based and struggles with complex tables and multi-column layouts; it can be swapped for the official PP-DocLayoutV3.
  • Only five consistency relations are supported (sum, product, words vs figures, per-line product, document total); no division.
  • Reconciliation compares field values only and does not understand clause semantics. TraceCell catches "copied wrong", not "written badly".
  • Confidence is a ranking score, not a probability: 0.9 does not mean 90% correct.
  • Jev cannot judge seals and graphics; those regions rely on rules and humans.

Project info

Author
logicore-code