← all articles

Extracting fields from invoices and receipts

One job, start to finish

Pulling fields out of invoices and receipts is one of the most common document jobs people hand to a language model. Supplier invoices arrive by email as PDFs. Staff photograph receipts for expense claims. Someone has to get the supplier name, invoice number, dates, line items, tax and total into an accounting system, and doing it by hand is slow and tedious.

Models are good at this now, and the general techniques are well covered: getting structured output that validates, and parsing PDFs into something a model can read. This piece doesn’t repeat those. It applies them to one concrete workload from start to finish, because invoices have specific problems that general advice doesn’t reach.

Those problems are mostly about correctness. An invoice extraction is judged on whether the numbers are right, whether they add up, and whether the right amount gets paid to the right supplier on the right date. A model that reads a total as 1,250.00 when it’s 12,500.00 has produced perfectly valid JSON and a serious error.

So the design principle throughout is that the model extracts and your code checks. Every field that can be verified independently gets verified, every document that fails a check goes to a person, and the pipeline keeps enough evidence to explain every number it produced.

I’ll walk through it in the order a document moves: intake, reading, extraction, normalisation, reconciliation, review and learning from corrections.

A worked document, end to end

It helps to follow one document through every stage. This one is invented, but its problems are typical.

A supplier invoice arrives as a two-page scanned PDF attached to an email. Intake classifies it as a single invoice, not a credit note or statement, and checks the scan quality: the text is legible after deskewing, so it moves on.

The reading step produces text for both pages. Page one has the supplier’s letterhead, the invoice number, the date and most of the line items. Page two has the remaining lines, the subtotal, tax and total, and the supplier’s bank details.

The model extracts the header fields and line items. The supplier’s name and tax number come back cleanly. The invoice date comes back as the raw string 04/05/2026, normalised by the model to the fourth of May. The total comes back as the raw string 2.340,00, normalised to two thousand three hundred and forty.

Normalisation in code agrees on the total, because the supplier is in a country that writes decimals with a comma. It checks the date against the supplier’s previous invoices, which use day-first dates, and agrees on the fourth of May.

Reconciliation runs. The line totals add up to the subtotal, but the subtotal plus tax is off from the total by a small amount. Looking closer, there’s a delivery charge on page two that the schema had no field for, so the model left it out.

The document goes to review with the failed check highlighted. The reviewer adds the delivery charge, approves the invoice, and notes the pattern. The next week, the schema gets a shipping field, and the test set gets this document.

That’s the whole pipeline in miniature.

What you’re actually extracting

Start by deciding the fields, because the schema drives everything after it.

Header fields are the ones that appear once per document: supplier name, supplier tax or registration number, invoice number, invoice date, due date, purchase order number, currency, subtotal, tax amount, total, and payment details such as a bank account reference. Receipts usually have fewer, typically the merchant and date, the total and tax, and sometimes the payment method.

Line items are the rows: description, quantity, unit price, line total, and sometimes a tax rate or product code per line.

Be selective. Every field you ask for is a field the model can get wrong and your reviewers must check. If your accounting process only needs the supplier, the date and invoice number, and the net, tax and total amounts, extracting line items adds work and error surface for no benefit. Some teams need line items for cost allocation or purchase order matching; many don’t.

For every field, write down what it means in your context. Is “date” the invoice date or the tax point? Is “total” inclusive of tax? What happens when there’s a discount line, a shipping line or a rounding adjustment? Those definitions become the field descriptions in your schema, which the model reads as instructions.

Decide how to represent absence. An invoice without a purchase order number should produce an explicit null, not a guess. Make every field nullable where the document might legitimately not contain it, and tell the model to return null rather than infer.

Intake and the documents you’ll really get

The documents arriving at your pipeline will be messier than your test samples, and it’s worth planning for the range.

Digital PDFs generated by accounting software are the easy case. They contain real text, often with a consistent layout from each supplier. Text extraction works well, and the model has clean input.

Scanned PDFs are images inside a PDF wrapper. There’s no text layer, or there’s a poor one from a scanner’s built-in OCR. You need OCR or a vision-capable model to read them.

Phone photos of receipts are the hardest. They’re skewed, creased, shadowed, partly out of frame, and thermal receipts fade. Some will be unreadable no matter what you use.

Then there are the odd cases: multi-page invoices, PDFs containing several invoices, invoices with a remittance slip attached, credit notes that look like invoices, statements that list several invoices, and emails where the invoice is in the email body rather than an attachment.

Build intake to classify before extracting. A quick first step, with rules, a small model, or both, can decide whether a document is an invoice, a credit note, a receipt, a statement or something else, and whether it contains one document or several. Credit notes in particular need to be caught, because extracting one as an invoice produces a positive amount where a negative one belongs.

Keep the original file for every document, unchanged, so every later step can be traced back to it.

Getting text or an image the model can use

The next step turns each document into input the model can read, and the route depends on the document type.

For digital PDFs, extract the text with a PDF library, preserving layout as much as possible. Invoices rely heavily on spatial layout: a number’s meaning often depends on the label to its left or the column header above it. Extraction methods that keep rows and columns aligned give the model a much better chance than ones that dump text in reading order.

For scans and photos, the choice is between running OCR and sending the text to a model, or sending the image to a vision-capable model directly. Each has trade-offs in cost, predictability and accuracy on hard images, and that decision deserves its own treatment. For this pipeline, what matters is that whichever route you take, you keep a record of what the model actually saw: the extracted text or the image.

Pre-processing helps with photos. Deskewing, cropping to the document and adjusting contrast can make a real difference to both OCR and vision models.

Check quality before extraction. If OCR returns very little text, or the text is mostly garbage characters, or the image is very small or blurred, send the document straight to human review rather than asking the model to extract from noise. A model given unreadable input will often still produce confident-looking output.

For multi-page documents, include all the pages. Totals are usually on the last page, and line items may span several.

The extraction prompt and schema

With readable input, the extraction call itself is fairly simple. The care goes into the schema and the instructions.

Use structured output with a schema that matches your field list. Give every field a clear name and a one-sentence description that includes your definition. For dates, say which date. For totals, say whether tax is included.

Ask for values as they appear, plus a normalised version. For amounts, that means the raw string from the document, such as “1.250,00 €”, alongside a parsed number. For dates, the raw string, such as “03/04/2026”, alongside an ISO date. Keeping the raw value makes review and debugging much easier, and it lets your code check the model’s parsing.

Ask for evidence where it’s practical. A short quoted snippet of the text around each key value, or a page number, helps reviewers find it quickly. Keep these short, since they add output tokens on every document.

Tell the model what to do with ambiguity. If a field can’t be found, return null. If there are two candidate totals, such as a total and a total due after a deposit, describe both in the schema so the model knows which is which. If the document seems to be something other than an invoice, say so in a document-type field.

Use a low temperature, since you want the same answer for the same input.

Keep the system prompt stable and put the document text last. That structure suits prompt caching on providers that support it, which lowers cost when you process many documents with the same instructions.

Normalising currencies and amounts

Amounts are where the most consequential errors happen, and a lot of them come from number formats.

Different locales write numbers differently. In many English-speaking countries, 1,250.50 means one thousand two hundred and fifty point five. In much of Europe, the same value is written 1.250,50, and 1,250 can mean one point two five. Some formats use spaces or apostrophes as thousands separators. A model that misreads the convention can be off by a factor of a thousand.

Don’t leave this entirely to the model. Take the raw string it extracted and parse it in code, using the supplier’s country or the invoice’s currency as a hint for the convention. If your parsed value and the model’s normalised value disagree, flag the document.

Currency needs the same care. Symbols are ambiguous: a dollar sign could be several currencies, and some currencies share symbols. Prefer an explicit ISO currency code if the document shows one. Otherwise, infer from the supplier’s country, the tax registration format or your own supplier records, and flag the document if you can’t be sure.

Watch for amounts with no decimal places in currencies that normally have them, and currencies that normally have none or three. Your parser should know the expected decimal places per currency.

Negative amounts deserve attention too. Credit notes, discounts and refunds may show amounts in brackets, with a trailing minus sign, or with a label like “CR”. Make sure your parsing handles each, and that a credit note’s total ends up negative in your system.

Dates and the day-month problem

Dates cause a smaller number of errors than amounts, but they’re just as easy to get wrong and can be just as costly for payment terms.

The classic problem is day-month order. 03/04/2026 is the third of April in many countries and March the fourth in others. For days above twelve, the order is unambiguous. For days twelve and below, it isn’t, and a model can’t reliably tell from the date alone.

Resolve it with context. The supplier’s country is usually the best signal. A consistent format across other dates on the same invoice helps: if the due date is 25/04/2026, the invoice date on the same document is probably also day-first. Your own records of previous invoices from the same supplier are the strongest signal of all.

Parse dates in code from the raw string, just as with amounts, and compare with the model’s normalised value. Flag disagreements.

Then apply sanity checks. An invoice date in the future, or years in the past, is suspicious. A due date before the invoice date is wrong. A due date that doesn’t match the supplier’s usual payment terms may be worth a look.

Watch for other date-like fields. Invoices often show a delivery date, an order date, a tax point and a print date. Your schema descriptions should make clear which one you want in each field, and it helps to ask for the label next to the date as part of the evidence.

Making the totals reconcile

This is the step that turns an extraction into something you can trust: checking that the numbers agree with each other.

Invoices contain internal redundancy. The line totals should sum to the subtotal. The subtotal plus tax should equal the total. Each line’s quantity times unit price should equal its line total. Tax should equal the subtotal times the applicable rate, give or take rounding and mixed rates. Those relationships give you free checks that don’t depend on the model being right.

Implement them in code after extraction. For each check, allow a small tolerance for rounding, typically a cent or two per line in currencies with two decimal places. Record which checks passed and which failed.

When checks pass, you have strong evidence the extraction is correct, because it’s unlikely that several misread numbers would happen to still add up. When they fail, the document goes to review, with the failed check highlighted.

Some invoices legitimately don’t reconcile in the simple way. Discounts applied at the total level, shipping charges listed separately, deposits already paid, rounding adjustments, and mixed tax rates all complicate the arithmetic. Handle the common patterns explicitly in your schema, with fields for discount, shipping and deposit, and include them in the checks. Treat anything else that doesn’t reconcile as a review case.

If you only extract header fields, you still have one check: subtotal plus tax equals total. It’s worth a lot.

Checking against what you already know

Beyond internal consistency, you can check an extraction against your own records, which catches errors the arithmetic can’t.

Match the supplier. Look up the extracted supplier name and tax number in your supplier list. A tax number that matches a known supplier gives you a reliable identity. A name that matches no one, or a tax number that belongs to a different supplier, is a flag.

Check for duplicates. Search for an existing invoice from the same supplier with the same invoice number, or the same total and date. Duplicate invoices turn up often, since suppliers resend them and staff forward the same email twice. Paying twice is an expensive mistake.

Match purchase orders. If the invoice references a purchase order, check that it exists, belongs to this supplier, and that the amount is within the order’s value.

Check payment details. If the invoice shows bank details, compare them with the details on file for that supplier. A change in bank details on an invoice is a well-known fraud pattern, and it should always trigger human verification through a separate channel, never an automatic update.

Compare with history. An amount far outside the supplier’s usual range, or a new currency, or unusual payment terms, is worth a look.

These checks need your data, which is why they belong in your code, not in the prompt.

Deciding what goes to a person

With extraction, normalisation and checks in place, the key design decision is which documents a human sees.

The simplest rule is: any failed check goes to review. That includes failed reconciliation, disagreement between the model’s parsing and yours, an unmatched supplier, a possible duplicate, a missing required field, a low-quality input, and any change in bank details.

Beyond that, some teams send every document above a certain amount to review regardless, since the cost of an error scales with the amount. Some send every document from a new supplier. Some send a random sample of passed documents, so reviewers keep checking the automated path.

Avoid relying on the model’s own confidence scores. Asking a model how confident it is in each field produces numbers that look useful but often don’t track actual accuracy well. The independent checks are much more reliable signals.

Make review efficient. Show the reviewer the original document next to the extracted fields, highlight the fields that failed checks, and show the evidence snippets. Let them correct a field and approve in a few clicks. A good review screen matters more to overall throughput than a small improvement in extraction accuracy.

Track the review rate over time. If it’s very high, the checks may be too strict or a particular supplier’s format may be causing trouble. If it’s very low, check that the sample of passed documents is still being reviewed.

Receipts are a different problem

Receipts share fields with invoices, but they behave differently enough to deserve their own handling.

They’re usually photos, not PDFs, so every receipt goes through the image route, with all the usual trouble from skew and shadows, creases and fading. Thermal paper fades over weeks, and some receipts are close to blank by the time anyone photographs them.

They have less structure. There’s rarely an invoice number, the merchant name may be a logo, and the tax may be shown only as a rate or embedded in each line. Many small receipts show only a total.

They’re often in a mix of languages and currencies, since expense claims include travel. The date and number format problems described earlier are more common, and the supplier-history signal that helps with invoices usually isn’t available for a café visited once.

And they come in bulk, attached to expense claims, often by people who’d rather not spend time on them.

That suggests a lighter approach. Extract fewer fields: merchant, date, total, currency and tax if shown. Rely more on the checks you can do: that the date falls within the claim’s period, that the amount matches what the employee typed into the claim, that the currency fits the country of travel, and that the same receipt hasn’t been submitted before.

The employee’s own entry is a strong cross-check. If the model’s extracted total matches what they claimed, that’s good evidence. If it doesn’t, someone looks.

Handling line items without drowning in them

Line items multiply everything, from output tokens to the time reviewers spend checking. If you need them, a few practices help.

Extract line items as an array in the schema, with each item’s description and quantity, its unit price and its line total, plus optional fields like tax rate and product code. Keep descriptions as they appear rather than asking the model to clean them up.

Long invoices can have many lines, sometimes hundreds. That produces a lot of output tokens, which are usually the expensive side of the bill, and increases the chance of a skipped or duplicated line. For very long invoices, consider extracting page by page and combining, then running the reconciliation checks on the combined result.

Use the reconciliation checks at line level. Quantity times unit price should equal the line total. The sum of line totals should match the subtotal. When the sum doesn’t match, the most common cause is a missed or duplicated line, and reviewers can usually spot it quickly if the extracted lines are shown next to the document.

Watch for lines that aren’t items: headers repeated on each page, subtotal rows within the table, notes and blank rows. Your schema description should say to skip them.

If you need line items only for some suppliers or some purposes, extract them only then. A two-pass approach, header fields for every document and line items only when needed, keeps cost and review load down.

Security and privacy in the pipeline

Invoices and receipts carry sensitive information, and the pipeline should treat them that way.

Invoices contain bank account details, tax numbers, names, addresses and sometimes information about what your company buys and at what price. Receipts can reveal where employees were and when. All of this may be personal data under privacy law, and some of it is commercially sensitive.

Check your model provider’s data terms before sending documents. Look for whether inputs are retained, for how long, whether they may be used for training, and whether a human might review them. For a production pipeline, a paid plan with clear data commitments is the right place for this work.

Control what you log. Debug logs that store full document text or images create a second copy of sensitive data, often with weaker access controls than the documents themselves. Log extraction results and check outcomes, and keep full documents only in the system designed to hold them.

Be alert to prompt injection. An invoice is text from an outside party, and a malicious document could contain instructions aimed at the model, such as text telling it to change the bank details or the total. Structured output and independent checks limit what such text can achieve, and bank detail changes should never be applied automatically in any case. Treat the document’s content as data to extract, never as instructions.

And restrict who can approve. Review screens that allow editing amounts and bank details need proper access control and an audit trail.

Cost and throughput

Invoice extraction is usually cheap per document, and it can still become a noticeable cost at volume. It’s worth doing the arithmetic.

For each document, the input is the system prompt, the schema, and the document’s text or image. Text from a one-page invoice is modest. Images cost more on most vision APIs, and multi-page scanned invoices more still. Output is the extracted JSON, which grows with the number of fields and especially with line items.

Multiply by the listed prices for your chosen model and your monthly volume. Then compare with what the manual process costs. For most teams, model cost per document is small next to staff time per document, and the question is really about accuracy and review rates.

Several things lower cost. Prompt caching for the stable instructions and schema, where your provider supports it. A smaller model for simple, well-structured digital invoices, with a larger one reserved for hard scans. Skipping line items when you don’t need them. Batch processing for documents that don’t need immediate results, since many providers discount batch requests.

If you process large batches, watch your provider’s rate limits and add a queue with retries for rate-limit errors.

And count review time as part of the cost. A cheaper model that sends more documents to review may cost more overall.

Posting to the accounting system

The last step is getting approved data into your accounting or payments system, and it has its own traps.

Map fields carefully. Your accounting system has its own codes for suppliers and tax rates, and for currencies and expense categories. The extraction gives you names and numbers; a mapping step turns them into the codes the system expects. Unmapped values, such as a tax rate your system doesn’t recognise, should stop the posting and go to review.

Post idempotently. If the posting step fails and retries, it shouldn’t create a duplicate entry. Use the invoice’s own identity, supplier plus invoice number, as a key, and check before creating.

Keep the link back. Every posted entry should reference the original document and the extraction record, so an auditor or a colleague can see where each number came from and who approved it.

Separate approval from payment. An extracted and reviewed invoice is a record of what a supplier has asked for. Paying it is a separate decision, usually with its own approval rules. Keeping the two apart means an extraction error can’t turn directly into money leaving the account.

Handle credit notes and adjustments properly. A credit note should reduce what’s owed to a supplier, linked to the invoice it adjusts where possible, and your posting logic should treat negative amounts deliberately rather than as an edge case.

Finally, reconcile periodically. Compare what the pipeline posted with supplier statements. Any invoice on a statement that never made it into your system, or any posted invoice the supplier doesn’t list, points to a gap.

Learning from corrections

Every correction a reviewer makes is information about where the pipeline is weak, and capturing it is how the system improves.

Log every correction: which document, which field, what the model extracted, what the reviewer changed it to, and why if they say. Over a few weeks, patterns appear. Perhaps one supplier’s invoices always confuse the date format. Perhaps discounts are consistently missed. Perhaps a particular receipt layout defeats the OCR.

Fix the patterns at the right level. Supplier-specific issues can often be handled with a per-supplier hint in the prompt, such as a note that this supplier uses day-first dates or lists shipping separately. Schema issues call for clearer field descriptions or new fields. Input issues call for better pre-processing or a different reading route for those documents.

Build a test set from real documents, especially the ones that failed. Keep each document with its correct values as confirmed by a reviewer. Before changing the prompt, the schema or the model, run the whole set and compare. That turns every improvement into something you can measure, and it catches regressions when a provider updates a model.

Be careful about sensitive data in the test set. Invoices contain supplier bank details, customer names and addresses. Store the set with the same care as the original documents.

Resist the urge to fine-tune early. For most teams, better prompts, better checks and per-supplier hints get most of the way there at much lower cost and complexity.

What to do this month

If you’re building or improving an invoice extraction pipeline, here’s a sequence.

Define the fields you actually need, with a written definition for each, and make every field nullable where it can legitimately be missing.

Add a classification step at intake that separates invoices from credit notes and receipts, and catches statements and multi-document files.

Keep raw values alongside normalised ones, and parse amounts and dates in your own code as a cross-check, using the supplier’s country and history.

Implement reconciliation checks: lines to subtotal, subtotal plus tax to total, quantity times price per line.

Check against your records, starting with the supplier match and duplicate invoice numbers, then purchase orders and bank details.

Send every failed check, and every bank detail change, to a human, with a review screen that shows the document next to the fields.

Log corrections, build a test set from them, and re-run it before any change.

We compare document-capable models and their pricing per page and per token, which helps when you’re choosing a model for extraction work, at AI Tool Gazette.

for builders
Running agents or scrapers at scale?

AI pipelines that crawl, research, or automate the web hit rate limits and geo-blocks fast. Singapore Mobile Proxy runs real 4G/5G mobile IPs that carriers still trust.

see plans →
read on
More from the Gazette

Tool reviews, model and pricing news, and build guides for people shipping real things with AI.

browse all articles →