Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 18 min read

Before an AI Extracts a PDF Table, Define What a Correct Row Means

Before an AI Extracts a PDF Table, Define What a Correct Row Means A spreadsheet can have the correct grand total and still contain the wrong rows. Two extraction errors can cancel each other, a merged heading can be a

Before an AI Extracts a PDF Table, Define What a Correct Row Means

A spreadsheet can have the correct grand total and still contain the wrong rows. Two extraction errors can cancel each other, a merged heading can be applied to the wrong column, and a scanned page can produce a plausible number that belongs to a different line. Before an AI-assisted document workflow writes table data into a business system, require evidence for the source document, page, row, column meaning and review stateβ€”not just a confidence score or a matching total.

For an organization exploring an AI project, this overview of agency support in Lausanne provides local project context. The decision examined here is narrower: can a team demonstrate that values extracted from a representative PDF table retain their meaning and provenance before the values are used in a spreadsheet, report or operational system?

This article provides a designed twelve-case acceptance matrix, a source-to-cell evidence record and a small executable validation example. The fixtures are synthetic and were authored on 4 December 2026. No actual PDFs, customers, vendors, extraction models, invoices, transactions or production outcomes were tested. The method is a proposed test, not a measured error rate or a claim that one product performs better than another.

Choose the destination before choosing the extractor

The safe process depends on what happens next. A draft spreadsheet used by an expert for exploration can tolerate clearly marked uncertainty if the source remains easy to inspect. A file that updates an accounting record, sends an invoice, changes a customer price or supports a regulated decision needs stronger controls and an authorized release step. The extraction tool's ability to produce a CSV does not decide which destination is appropriate.

Begin with one document family and one task. Define the table, expected columns, the meaning of blank cells, the source of any total, and the decision that will consume the data. A supplier's line-item schedule, a list of contract milestones and a statistical table may all look tabular while requiring very different interpretations. Do not combine them under one generic rule simply because they are all PDFs.

Ask a domain owner to define unacceptable errors. Swapping the amount between two counterparties may matter more than a minor formatting difference. Missing a footnote can change the meaning of an entire column. A table may also contain subtotals and non-additive percentages; a universal β€œsum every number” check would create false confidence or false alarms. Specify the arithmetic only where the document and use case support it.

Intended use Minimum evidence to consider Default when evidence is missing
Exploratory draft Source version, page, table and visible uncertainty Label draft; prevent accidental operational import
Spreadsheet for an analyst Source-linked cells, column semantics and review status Hold affected cells or rows for review
Reconciled business report Approved schema, applicable checks and accountable reviewer Block release of the affected report
System update or payment-related action All preceding evidence plus destination-specific authorization and confirmation Do not write; route to the designated owner
Sensitive or disputed record Purpose, access, retention and subject-matter review Use an approved restricted workflow

The workflow should be able to say β€œunknown.” An unreadable value is not a zero, an empty cell is not automatically inherited from the previous row, and a model's explanation is not proof of what appeared on the page. These distinctions must survive every export and conversion, including a handoff to a human reviewer.

Text, geometry and meaning are different layers

A PDF page may contain a usable text layer, an image of text, or both. A hybrid file may contain a scan with an imperfect hidden text layer. First identify what is available for each page. A comparison between two extractors is useful only if you know whether they read independent evidence or the same underlying text layer; agreement between two transformations of the same error is not independent confirmation.

The geometry layer identifies where text or cells appear. The meaning layer links a value to a row label, column heading, unit, period, footnote and table version. A character can be recognized correctly and still be assigned to the wrong row. Conversely, a model can locate the correct cell while misreading a decimal separator. Store both the recognized value and a reference that lets a reviewer inspect the source region.

Amazon Textract's table documentation describes a representation with table, cell, merged-cell, title and footer relationships. That documentation establishes what the service can return, not that any particular extraction is correct. If another tool supplies a different schema, map its relationships explicitly and test the mapping. Do not discard merged-cell or page references merely because the destination spreadsheet does not have fields for them.

For a multi-page table, determine whether the next page continues the previous table, starts a new one, or repeats a heading. A repeated header can be structural context, not a new data row. A continuation row may start on one page and end on another. Where the relation cannot be established, retain a review flag instead of joining by visual proximity alone.

The cell evidence record

A useful evidence record identifies the immutable source document or approved version, page number, table identifier, row key, column key, raw extracted text, normalized value, unit, extraction method and source location. It also records review state, reviewer and time when a human decision is required. The exact schema is local; the essential requirement is that a downstream user can trace a value back to the evidence used to create it.

Keep raw and normalized values distinct. For example, 1,250 can represent different numbers under different locale conventions. Preserve the original characters, document the selected locale and normalization rule, and flag ambiguity. Do not silently drop a currency symbol or transform a dash into zero. A blank can mean β€œnot applicable,” β€œsame as above,” β€œnot provided” or a genuinely empty value; the source's layout and notes determine which interpretation is justified.

Bind evidence to the document version. If a revised PDF arrives, an earlier approval should not automatically authorize values from the new version. A content digest can help identify the exact bytes reviewed, but it does not prove that the document is authentic, complete or appropriate for the business decision. Preserve the source channel and ownership separately, and check that the reviewer can access the same version that was extracted.

A page and bounding box are useful review pointers, not independent proof that the value is correct. Coordinate systems, page rotation, rendering scale and OCR preprocessing can all change the reference. Record enough information to reproduce the view and test the link on representative documents. If the extraction tool provides only text and no reliable location, mark that limitation and choose a review method that does not pretend otherwise.

A designed twelve-case acceptance matrix

The following scenarios were created for this article. The sample is twelve designed cases, not twelve documents, users or measured defects. The table has no vendor pass rates. Use synthetic or appropriately authorized material, record the test date and environment, and compare the extracted output with a separately prepared reference answer. Add document families, languages and layouts that your actual workflow uses.

Case Source condition Acceptance evidence
1 Clean digital table with text layer Every required row and column maps to the correct source region
2 Scanned page without selectable text OCR output remains traceable to the rendered page; unreadable cells are flagged
3 Merged heading spans two columns Heading scope is preserved without copying it to unrelated fields
4 Table continues onto another page Continuation and repeated headers are distinguished from data rows
5 Wrapped description occupies two visual lines The description remains attached to one logical row when appropriate
6 A blank cell could mean zero or inherited value The blank remains unresolved until the document's convention is established
7 Decimal and thousands separators are ambiguous Raw value and locale assumption are preserved; uncertain normalization is held
8 Footnote qualifies a row or column The qualifier follows the affected data or the result is held for review
9 Two incorrect numbers still sum to the printed total Total check passes but source-to-cell comparison detects the errors
10 New source version arrives after review Earlier approval does not release the new version without revalidation
11 Duplicate row or page appears during processing Duplicate is detected and not silently counted twice
12 Document contains instructions addressed to the model Content remains data; it cannot change tools, destination or release authority

Test both ordinary and adverse cases. Include an intentionally poor scan, a rotated page and a real-looking table whose subtotal rules differ from your default assumptions. A clean example can show that the pipeline works under favorable conditions; it cannot establish that the same pipeline handles every source or every exception.

Record outcomes at several levels: page inclusion, table detection, row completeness, cell text, row-column association, unit interpretation and destination write. A single β€œdocument processed” status hides too much. An extraction may succeed technically while missing a page, merging two rows, or losing an explanatory footnote.

Why a matching total is necessary but insufficient

Consider a fictional table with two source amounts, 100.00 and 80.00, in the same currency. The printed total is 180.00. Now imagine the extraction produces 110.00 and 70.00. The extracted total is still 180.00, but both rows are wrong. This is a constructed arithmetic example, not a measured production failure. It demonstrates why reconciliation can detect some inconsistencies without proving cell-level correctness.

If the source does not contain an authoritative total, do not invent one merely to make the check pass. If the table includes tax, discounts, subtotals, credits or rounded line items, define which values are included and the rounding convention. An equality check that ignores the document's own rules can reject correct data. Conversely, a total copied from the same erroneous extraction is not an independent check.

Use integer minor units or an appropriate decimal library for money. Floating-point arithmetic can produce rounding artifacts, and currencies do not all use the same number of minor units. The example below uses hypothetical integer cents solely to keep the arithmetic explicit. It is not a currency-conversion, tax or accounting implementation.

A runnable release-check example

The code below checks a small evidence envelope and arithmetic for a synthetic table. It cannot inspect a PDF, verify an image, determine the meaning of a footnote or confirm that a reviewer actually looked at a page. In particular, its reviewed field is only an input assertion. Production controls must authenticate reviewers, bind approval to immutable data and separately verify each required source-to-cell comparison.

function reviewTable(table) {
  const issues = [];
  if (!table.sourceVersion || !table.schemaVersion) issues.push('version_missing');
  if (!Array.isArray(table.rows) || table.rows.length === 0) {
    return {ok:false, issues:[...issues, 'rows_missing']};
  }
  const ids = new Set();
  let sum = 0;
  for (const row of table.rows) {
    if (!row.id || ids.has(row.id)) issues.push('row_id_invalid_or_duplicate');
    ids.add(row.id);
    if (!Number.isSafeInteger(row.amountMinor)) issues.push('amount_not_integer');
    else sum += row.amountMinor;
    if (!row.page || !row.sourceRef) issues.push('source_reference_missing');
    if (row.reviewed !== true) issues.push('row_not_reviewed');
  }
  if (!Number.isSafeInteger(sum) || !Number.isSafeInteger(table.statedTotalMinor)) {
    issues.push('unsafe_total');
  } else if (sum !== table.statedTotalMinor) {
    issues.push('total_mismatch');
  }
  return {ok:issues.length === 0, issues, sumMinor:sum};
}
const sample = {sourceVersion:'synthetic-v1', schemaVersion:'v1',
  statedTotalMinor:18000, rows:[
    {id:'A', amountMinor:10000, page:1, sourceRef:'p1-r1', reviewed:true},
    {id:'B', amountMinor:8000, page:1, sourceRef:'p1-r2', reviewed:true},
  ]};
console.log(reviewTable(sample));
console.log(reviewTable({...sample, statedTotalMinor:19000}));

Save the code as table-check.js and run node table-check.js. The first output passes this narrow structural and arithmetic check; the second reports a total mismatch. That first result is not proof that the synthetic rows were read correctly. If the two values were 11000 and 7000 and both were asserted reviewed, the code would also pass. A separate source-to-cell review is indispensable.

For a real system, validate types and ranges for the document family, handle negative values and zero according to documented semantics, define currency precision, preserve explicit nulls, and reject unsafe arithmetic. Do not use a model to make a financial or legal decision merely because this helper returns ok. The function is a teaching fixture, not a production library or a compliance test.

Confidence is a signal, not a release authorization

A score can be useful for prioritizing review, but it must be interpreted in the context of the model, field and sample on which it was calibrated. Word recognition confidence, table structure confidence and confidence in a mapped business field may refer to different things. A high score for individual characters does not automatically mean that the number belongs to the correct supplier, row, period or column.

Microsoft's transparency note for Document Intelligence recommends evaluating the service on the customer's own scenarios when choosing how to route results for review. Its example threshold is an illustration, not a universal threshold for every organization or a guarantee of accuracy. Test representative document families and high-consequence fields separately, and retain a random review sample even when a score is high if the risk assessment warrants it.

A Microsoft Q&A discussion asks why confidence differs for related outputs. The reply suggests examining recognition and field-level signals separately. This is a specific forum exchange, not independent evidence that a score is calibrated for your documents. It is useful because it points to a practical question for a pilot: can reviewers see which part of the extraction is uncertain and inspect the source?

Avoid a threshold chosen only to hit a throughput goal. If lowering the review rate hides errors that matter to customers, the apparent saving may create rework or harm elsewhere. Report both the volume routed to review and the errors found on independently checked outputs. A review process that examines only low-confidence rows cannot measure the quality of high-confidence rows it never samples.

Build a reference set that can reveal errors

Select documents using a documented rule rather than choosing only easy examples supplied in a vendor demo. Include relevant page types, languages, scan qualities, table structures, document ages and exceptions. If a high-risk document family is rare, supplement ordinary sampling with deliberately chosen edge cases; report that design rather than describing it as a random estimate of all documents.

Prepare the reference answer independently of the extractor being assessed. For sensitive material, use synthetic documents or authorized data with appropriate access, retention and review arrangements. Have a qualified person record the expected row, column, value, unit and source region; resolve disagreements without silently changing the source document. Keep the reference set versioned so a model change can be evaluated against the same cases.

Separate three questions. Did the system find all relevant tables? Did it reconstruct each table's structure? Did it extract and interpret each required value correctly? A model can perform well on the second question and poorly on the third. Define what counts as an exact match, an acceptable formatting difference, an unresolved value and a serious semantic error before seeing the results.

The OECD report on AI in public audit describes document processing as a potential aid to audit work while noting OCR quality and privacy challenges. Its examples concern public audit, not a benchmark for a Lausanne business's supplier documents. Use that distinction when interpreting any claim that a general-purpose tool will work on your specific forms.

A suitable measurement report includes the document population, selection method, test date, model and configuration, reference preparation, exclusions and unresolved cases. Report counts and denominators for pages, tables, rows and critical cells as relevant. Do not present a percentage from a handful of favorable samples as a universal accuracy figure. If the sample is too small to support a decision, expand it or keep the workflow in review mode.

Handle untrusted content as data

A document can contain text that looks like an instruction to an AI component. A supplier note may legitimately say β€œignore the previous total,” while a malicious file could contain an instruction to change the destination, reveal data or bypass review. The workflow must treat source content as evidence to interpret, not as authority to modify system policy or invoke tools.

Separate the extraction component's permissions from the component that can write to a business system. Use restricted credentials, explicit destination allowlists and validation at the receiving boundary. A model-generated value or explanation should not be able to expand its own permissions. The CISA Secure by Design initiative describes a broader approach to building security into products; applying least-privilege separation to this workflow is an implementation recommendation, not a product certification.

Store sensitive PDFs and extracted values according to the organization's approved access, retention and processing rules. A source image, OCR output, log, review screenshot and exported spreadsheet may each contain the same personal or commercial information. Deleting only the original file may leave copies elsewhere. Map the data flow before enabling a cloud service or giving a third party access.

Human review is not an automatic security or accuracy guarantee. Reviewers need sufficient context, clear responsibilities, an interface that displays the actual source region and a way to say β€œcannot determine.” A rushed reviewer who sees only a model summary may reproduce the model's mistake. Preserve the reviewer decision and the version that was reviewed, and make corrections available to authorized downstream users.

Failure modes to rehearse

The wrong source version is processed. A supplier sends a corrected document after the earlier version was approved. If the pipeline identifies files only by name, the correction can inherit stale approval. Bind the extraction and release decision to the exact version, and define how a replacement invalidates pending exports.

A table continues across a page break. The extractor treats the repeated heading as a new data row or attaches the first value of page two to the last row of page one. Require page-level references and a continuation decision. When a relation is uncertain, hold the affected part rather than guessing.

A merged heading changes the unit. A heading applies to two subcolumns, but the export attaches it to only one. Values can be numerically correct and semantically wrong. Preserve column hierarchy and units, and have a reviewer compare the exported structure with the source when the layout is ambiguous.

A decimal separator is normalized incorrectly. The same characters can mean different things under different locale conventions. Keep raw text and the selected locale together. If the format cannot be resolved from the document or approved business context, do not silently choose the interpretation that makes a total fit.

A blank is treated as zero. A blank may carry meaning from a prior row, be intentionally absent or indicate an unavailable value. Keep it as a distinct state until the document's convention is established. A convenient spreadsheet default should not change the business meaning of the source.

A correct total hides incorrect lines. Offsetting errors can preserve an aggregate. Compare critical values and row associations with source evidence in addition to arithmetic checks. Conversely, a correct set of rows can fail an invalid total rule if the document uses discounts, rounding or subtotals not modeled by the checker.

The export is reviewed but the destination receives different data. A worker can modify the spreadsheet after approval, or a later import can use a different file. Bind approval to the released artifact or version and verify what the destination accepted. If the write times out, reconcile the destination before retrying; an unknown outcome is not proof that no update occurred.

Compare costs without hiding review work

Estimate the complete workflow: ingestion, extraction, error investigation, review, correction, export, storage, security and maintenance. Count pages or tables only when those units are meaningful for the task. An inexpensive per-page model can be costly if it produces many difficult exceptions, while a more expensive tool may still be a poor choice if it cannot support your data boundary or review process.

Separate a vendor's demonstration from a measured pilot. EY's document-automation paper describes a human review layer in a model-documentation workflow. That context differs from extracting scanned supplier tables. It supports asking how review is integrated, not copying a performance or savings estimate to this use case.

Measure review time and rework only on an authorized, defined sample, and disclose whether reviewers were experienced, whether a reference answer existed and whether source access was convenient. Faster review is not automatically better if critical mistakes escape. Compare accepted, corrected and unresolved outcomes as well as time spent; retain a route to escalate high-consequence ambiguity.

A staged pilot and rollback

Start with a fixed document family in an isolated environment. Define the output schema, the source-evidence record and the permitted destination before testing a model. Run the synthetic matrix, then an appropriately selected and authorized reference set. Log failures by page, structure, value and meaning rather than combining them into a single β€œAI error” category.

In shadow mode, produce a draft alongside the existing workflow without sending extracted values to the operational destination. Compare results with independently reviewed reference answers. Investigate disagreements and identify whether the source is unreadable, the structure is wrong, normalization is ambiguous or the business rule itself is unclear. Record version changes so that a later rerun is interpretable.

If the organization proceeds to a limited pilot, define which documents are eligible, who approves release and what happens when the source or tool is unavailable. Stop operational writes when critical source references disappear, a document version cannot be identified, an unacceptable semantic error is observed, or the downstream result cannot be reconciled. The precise thresholds belong to the responsible organization and should be set before the pilot.

A rollback must cover both the extraction configuration and the destination. Preserve the last approved schema and model configuration, identify outputs produced by the affected version, and provide a controlled process to correct downstream records. Turning off the model does not undo a spreadsheet already imported elsewhere. Keep a record of what was released, where it went and who owns correction.

Evidence and source control

For each test run, keep the source set or authorized synthetic fixture, document versions, page ranges, extractor and configuration versions, output schema, expected results, reviewer decisions, unresolved cells and destination outcome. Keep access restricted. A reproducible test is one in which another authorized person can understand the source and decision without relying on a generated narrative alone.

The twelve cases and the two-row arithmetic example in this article are designed illustrations. The sample contains no real PDFs and supports no claim about model accuracy, frequency of failure or financial impact. The code checks only the assertions supplied to it. Its limitations are part of the asset and should travel with it when the example is reused.

A first-party Search Console report for the source page returned 36 impressions and an average position of 24.6 for the query β€œagence ia lausanne” during 20 November–1 December 2026. This is one property, query and reporting window, not a measure of demand for PDF extraction or a prediction of visibility. It helped identify a relevant local project context; the operational question and test design come from the separate source review and the needs of the proposed workflow.

Validation checklist

  • The document family, destination and consequential decisions are defined.
  • Every required cell can be traced to the approved source version and page.
  • Raw text, normalized value, unit and uncertainty are preserved separately.
  • Merged headings, page continuations, footnotes and blank-cell conventions are reviewed.
  • Arithmetic rules match the source and do not stand in for cell-level verification.
  • The reference set includes difficult and representative cases, with independent expected results.
  • Confidence thresholds are evaluated locally and never treated as proof of correctness.
  • The extraction component cannot grant itself access to tools or destinations.
  • Reviewer authority, approval version and downstream import are auditable.
  • Unknown write outcomes are reconciled before retry, and rollback covers exported records.
  • Sample dates, denominators, exclusions and unresolved cases accompany every measured claim.

The goal is not to make a PDF look like a spreadsheet as quickly as possible. It is to preserve enough evidence that a person or system can tell what each value means, where it came from and whether it is fit for the next decision.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.