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.

Another reader already did the reading: a model looking at the page image, an extraction API. This module does not read in its place. It takes each value it returned, under the label of its row, and says what the document prints there.

import { verify, verifyValues } from 'truecopy/verify';

One call

import { verify } from 'truecopy/verify';

const checked = await verify(file, [
  { value: '8 430', label: 'Total assets' },
  { value: '8 340', label: 'Total assets' },
  { value: '1 250', label: 'Inventories' },
  { value: '512', label: 'Goodwill' }
]);

On a three-line balance sheet that prints Inventories 1 250 1 180 and Total assets 8 430 7 990, run against truecopy 2.0.26:

confirmed     labelled: true   row: 3
contradicted  labelled: true   row: 3   printed: [ '8 430', '7 990' ]
confirmed     labelled: true   row: 2
not-found     labelled: false

The answers come back in the order the claims were given, one CheckedValue per ClaimedValue.

Standing: the three answers

  • confirmed: a row the label names prints the figure.
  • contradicted: the rows that open on the label print other figures, and every one of them was read with confidence. printed lists them.
  • not-found: neither. This is not a verdict on the value. It says the document, read this way, does not settle it.

A label is read letter by letter, so Inventor ies from a text layer still names Inventories. A label of one or two characters names nothing.

ClaimedValue

  • value: a number, or a string. A string with a digit and no letter is a figure; otherwise it is words.
  • label: the words that name its row. Without it a figure can only be found somewhere or not found, never contradicted, and found somewhere is a much smaller claim.
  • page: the page it was read from, 1 for the first. Left out, every page answers.

CheckedValue

  • standing: one of the three above.
  • labelled: whether a row the label names answered. A confirmed with false was claimed with no label: the value is printed, and nothing says on which row. A not-found with false under a label means the document prints that label nowhere.
  • page and row: where the answering row is, row counting from 1, so Table.rows[row - 1].
  • place and confidence: on a confirmed only, where the confirming cell sits and how far it was trusted on its own. The confidence is informative; the agreement of two readers is what confirmed it.
  • printed: on a contradicted only, the figures the row prints instead.

VerifyOptions

  • written: the decimal mark the claims are written with, when it is not the document’s. A model asked for JSON writes 1234.5 for a page that prints 1 234,5.
  • brackets: what brackets around a figure mean on this document. A sign unless said.

verify(file, claims, options?) and verifyValues(table, claims, options?)

verify reads the file itself, with the default cut and the confidence of each cell, and refuses the cut options on purpose: the confidence was measured on the default cut and claims nothing past it. It also takes the options of open.

verifyValues does the same on a reading you already hold. Read the table with confidence: true: without the score of each cell nothing is ever contradicted, except on a delimited file.

The MCP server carries the same check as verify_values.

What it cannot see

The column. A figure confirmed on its row may be last year’s: 8 430 and 7 990 sit on the same row, and either one is confirmed under Total assets.

Where to go next