New Tool Radar

AI Agents & Automation

How to Build a Document-Processing Agent That Extracts Invoice Fields

Build a document-processing agent that pulls invoice numbers, dates and totals into a spreadsheet, and checks the totals before it files them.

Schematic illustration with three step boxes: define the fields, extract and validate, and file the checked rows.

A document-processing agent reads invoices, extracts the fields your spreadsheet needs, and files the rows. The extraction is only half the job: the totals must be checked before filing, because an agent that files a wrong total creates a wrong record that looks authoritative. The check is to recompute each total from its line items and reject the rows that do not add up.

Before you start

A set of sample invoices, a spreadsheet or database to file the rows into, and a list of the fields to extract.

Define the fields to extract

List the fields the spreadsheet needs: invoice number, invoice date, vendor name, line items, subtotal, tax, total, and due date. For each field, write what it means and where it usually sits on the page.

Decide what happens when a field is missing: a missing due date becomes null, never an invented date.

Extract with a schema and validate the totals

Have the agent extract the fields into a fixed schema, with types for each field and an enum for the currency. Then validate every row in code: the total must equal the subtotal plus the tax, and the line items must add up to the subtotal.

Reject any row that fails validation and send it to a human queue with the invoice attached. A rejected row is a pause, not a failure.

File the checked rows and keep the source

File only the rows that pass validation, and keep a link from each row back to the source invoice, so any number can be traced to the page it came from.

Log the extraction rate: how many invoices were filed, how many were rejected, and why. A rising rejection rate means the invoices changed or the extraction broke.

Practice check: fictional Maple Corner invoices, 10 invoices, 8 fields each

The table below is fictional practice material, worked out by hand from the stated extraction. It is the expected result for the practice invoices, not a run of any agent.

Invoice Fields extracted Total check Verdict
INV-101 8 of 8 248.00 = 220.00 + 28.00 Pass – filed
INV-102 8 of 8 269.15 = 240.00 + 29.15 Pass – filed
INV-103 7 of 8 Due date missing, null Pass – filed with null
INV-104 8 of 8 312.40 vs 300.00 + 12.00 Fail – rejected, total wrong
INV-105 8 of 8 150.00 = 130.00 + 20.00 Pass – filed

Four of five invoices are filed and one is rejected: INV-104 states a total of 312.40 while its parts add to 312.00, so the row goes to the human queue instead of the spreadsheet.

Expected result. UNTESTED: the totals in the practice table are worked out by hand from the stated line items: 220.00 + 28.00 = 248.00, 240.00 + 29.15 = 269.15, 300.00 + 12.00 = 312.00, and 130.00 + 20.00 = 150.00. They are not measured by running an agent. Extract the fields from your own sample invoices, recompute every total from its parts, and file only the rows that pass.

Limits

  • A total that does not add up is a rejected row, not a rounding error: check the parts before you file.
  • A missing field becomes null, never an invented value: an invented due date is a wrong record.

Sources

See all