Documentation

From two lines to a reader that checks itself.

Start with the shortest thing that works. Reach for the next page only when something downstream starts acting on the rows.

npm install truecopy

Trusting a reading

How do you know the reading is right?

The checks that actually catch a wrong table extraction, which of them a library can run for you, and the one thing none of them prove. Written because the question has plenty of articles and almost no code.

Check what a model extracted

The rows came back from a model, not from this library. The check that can still say they are wrong costs one object, and it never looks at how they were obtained.

verify - check the values another reader returned

truecopy/verify

A model or an extraction API hands back values. verify reads the document itself and answers, for each value under the label of its row, confirmed, contradicted or not found.

cite - the rows a model read, and whether they carry the value

truecopy/cite

A model cannot produce a fact, only point at one. Number the rows, take back the numbers it cited, and look every value up in THOSE rows and nowhere else.

anchor - the passage a stored value came from, found again

truecopy/anchor

A value read once and served for months cannot re-run its extraction per reader. What proves it is the sentence, found again from a short anchor kept beside the value. The figures the value announces are checked against that sentence.

signature - the schema learned from the rows

truecopy/signature

A table describes itself. The row that breaks what every other row does is a total, a balance or a footer. Recognising it needs no list of words.

contract - what an honest reading looks like

truecopy/contract

You write three methods, and two of them have safe defaults. The pipeline enforces one rule. A reading that contradicts its document never comes back as sound.

kit - six rules, in your own test suite

truecopy/kit

An interface is dodged with a return null. An assertion is not. Drop the conformance kit into your gate with a corpus of your own documents.

schema - one declaration, two outputs

truecopy/schema

Write the schema once and get the check and the record type. Or bring the one you already wrote in Zod, Valibot or ArkType.

explain - see what the reading decided

truecopy/explain

The popular extractors have this feature, and the careful ones forget it. It prints text, not an image, so it goes into a terminal, a CI log, a bug report and a test.

classify - is this the kind of document expected

truecopy/classify

A statement quoting the word invoice in a transaction label must not be filed as an invoice. The precedence is stated rather than smuggled into an ordering.

columns and roles - what a column holds, and what it is

truecopy/columns · truecopy/roles

Count what each column contains once, then deduce what it is from that. Recognising a header label only works on issuers you have already seen.

pattern - domain knowledge as data

truecopy/pattern

Everything that varies by market, by issuer or by document family should be a value, not a branch. And a pattern off the wire is untrusted input applied to untrusted input.

The public bench - published tables, their truth, and every reader's score

Financial tables that issuers published, the truth their own filing tags carry, and what truecopy and four other readers make of them. One command replays it, and it shows where this library is wrong while saying it is not.