Technical

AI Invoice OCR vs Template OCR: Measuring Vendor-Bill Accuracy

How template OCR and AI invoice OCR read vendor bills, the common reasons extraction goes wrong, and a practical method to measure and improve accuracy before letting it touch your books.

Kalvyai Engineering · · Updated · 7 min read

AI Invoice OCR vs Template OCR: Measuring Vendor-Bill Accuracy (cover)
On this page

Every invoice extraction pipeline answers the same question. Given a PDF or photo from a supplier, what are the vendor, invoice number, dates, currency, line items, taxes and totals? Template OCR and AI OCR answer it differently, and they fail differently. This post covers how each works, where vendor-bill extraction breaks, and how to measure accuracy so you know when it is safe to rely on.

How template OCR works

Template OCR is rule-based. A typical pipeline looks like this:

  1. An OCR engine converts the image into text with bounding-box coordinates. If the PDF already contains a text layer, that text is used directly.
  2. The system identifies the vendor, usually by a keyword, a tax ID or text in a fixed position.
  3. It loads the template for that vendor: zones ("the invoice number is to the right of the label 'Invoice No'"), anchors and patterns.
  4. It reads values from those zones and applies formatting rules.

Strengths: deterministic, so the same input gives the same output. It is easy to explain why a value was read. Cost per page is low.

Weaknesses: you need one template per layout. When a vendor changes their billing software, the template can break without anyone noticing. A new vendor gets no extraction until someone builds a template. Line-item tables with a variable number of rows, or rows that wrap, are hard to handle with fixed zones.

How AI invoice OCR works

AI extraction replaces the per-vendor template with a model that understands document layout and language:

  1. Get text and layout: the embedded PDF text, OCR output, or the page image sent to a vision-capable model.
  2. Give the model a target schema with field definitions and ask it to fill it in.
  3. Receive structured output, usually JSON, sometimes with per-field confidence or the location the value came from.
  4. Normalize and validate the output with ordinary code.

Strengths: it works on layouts it has never seen. It handles label variations like "Bill No", "Tax Invoice #" or "Rechnungsnummer" without rules. It can read line tables without a template.

Weaknesses: it is not fully deterministic. It can return a plausible but wrong value, such as the PO number in place of the invoice number, or fill in a field that is not on the page at all. Model confidence scores are not always well calibrated. Cost and latency per page are higher, and if you use a hosted model, document data leaves your server, so check the provider's data terms.

The difference that matters

Template OCR fails loudly on unknown layouts (empty fields) and quietly on changed layouts. AI OCR tends to fail quietly, with confident wrong answers. Neither should feed accounting without a validation layer, and that layer is where most of the real engineering happens.

Why vendor-bill extraction fails

Input problems

  • Phone photos with skew, shadows, folds or low resolution.
  • Scanned PDFs with no text layer, versus digital PDFs that already contain text.
  • Multi-page bills where the line table spans pages and totals appear only on the last page.
  • Several documents in one PDF: invoice, delivery note and account statement together.

Ambiguous fields

  • Invoice number versus PO number, order number, delivery note number or customer account number.
  • Dates: is 03/04/2025 March 4 or April 3? Is it the invoice date, due date or delivery date?
  • Parties: every bill has two addresses. Models sometimes pick your company as the vendor because your name is prominent in the "Bill To" block.
  • Totals: subtotal, total before rounding, amount due after an advance, or a balance that includes previous dues.
  • Document type: credit notes look like invoices, and getting the sign wrong is a real accounting error.

Line items and tax

  • Discounts applied per line versus on the whole document.
  • Tax shown per line or only in a summary, multiple rates, tax-inclusive prices.
  • Units of measure: a box of 12 versus each.
  • Descriptions that wrap onto a second line and get read as a separate item.

ERP mapping problems

Extraction can be correct and the bill can still be wrong once it reaches the ERP:

  • The vendor name on paper does not match the partner record ("ABC Traders Pvt Ltd" versus "A.B.C. Traders").
  • The supplier's product code is not mapped to your product.
  • The tax label on the paper does not map cleanly to a tax record in your ERP.
  • Expense account or analytic choices are not on the paper at all.

Measure extraction and mapping separately. Otherwise you will tune prompts to fix what is actually a master-data problem.

How to measure accuracy

Step 1: Build a ground-truth set

  1. Collect real bills from recent months. Stratify them: high-volume vendors, long-tail vendors, phone photos, multi-page bills, credit notes, foreign-currency bills.
  2. Have someone from accounts key in the correct values in your target schema. This is the slow part, and it is worth it.
  3. Split the set. Use one part while you tune prompts and rules, and keep a held-out part that you only use for reporting.

Aim for enough documents in each segment that one odd bill does not swing the result. Pick a ground-truth sample size that suits your own vendor mix and bill volume.

Step 2: Fix the schema and normalization rules

Decide the exact output shape before you score anything:

JSON
{
  "document_type": "invoice",
  "vendor_name": "ABC Traders Pvt Ltd",
  "vendor_tax_id": "29ABCDE1234F1Z5",
  "invoice_number": "INV-2025-0412",
  "invoice_date": "2025-04-03",
  "due_date": "2025-05-03",
  "currency": "INR",
  "lines": [
    {"description": "Steel bracket 40mm", "quantity": 100, "uom": "each", "unit_price": 12.50, "discount": 0, "tax_rate": 18}
  ],
  "subtotal": 1250.00,
  "tax_total": 225.00,
  "total": 1475.00
}

Normalize both the truth and the prediction before comparing: dates to ISO format, amounts to two-decimal values, invoice numbers with spaces removed and upper-cased.

Step 3: Score at three levels

  • Field accuracy: for each field, count correct, wrong, missing and invented. A wrong value is worse than a missing one, because a missing value forces review while a wrong value can slip through.
  • Line-item accuracy: match predicted lines to true lines, then measure how many lines were found, how many extra lines appeared, and field accuracy on the matched lines.
  • Document accuracy: the share of documents where every header field is correct. This approximates "could have been posted without edits", and it is the number your accountants care about.

A minimal scoring script for header fields:

Python
from decimal import Decimal

HEADER_FIELDS = ['vendor_tax_id', 'invoice_number', 'invoice_date',
                 'due_date', 'currency', 'subtotal', 'tax_total', 'total']
AMOUNT_FIELDS = {'subtotal', 'tax_total', 'total'}
TOLERANCE = Decimal('0.01')

def normalize(field, value):
    if value is None or value == '':
        return None
    if field in AMOUNT_FIELDS:
        return Decimal(str(value)).quantize(Decimal('0.01'))
    if field in {'invoice_number', 'vendor_tax_id'}:
        return ''.join(str(value).split()).upper()
    return str(value).strip().lower()

def score_field(field, truth, pred):
    t, p = normalize(field, truth), normalize(field, pred)
    if t is None and p is None:
        return 'correct'
    if p is None:
        return 'missing'
    if t is None:
        return 'invented'
    if field in AMOUNT_FIELDS:
        return 'correct' if abs(t - p) <= TOLERANCE else 'wrong'
    return 'correct' if t == p else 'wrong'

def evaluate(pairs):
    stats = {f: {'correct': 0, 'wrong': 0, 'missing': 0, 'invented': 0}
             for f in HEADER_FIELDS}
    perfect_docs = 0
    for truth, pred in pairs:
        doc_ok = True
        for f in HEADER_FIELDS:
            result = score_field(f, truth.get(f), pred.get(f))
            stats[f][result] += 1
            doc_ok = doc_ok and result == 'correct'
        perfect_docs += doc_ok
    return stats, perfect_docs / len(pairs)

Score vendor identity on the matched partner record rather than the raw name string, since name formatting varies so much.

Step 4: Break results down by segment

Report per vendor, per input type and per field. An overall average can look fine while your largest vendor is wrong on every bill, or while phone photos fail far more often than digital PDFs.

Validation rules that catch errors

Extraction will never be perfect, so add checks that do not depend on the model:

Python
from decimal import Decimal

def validate(bill, partner, existing_keys, today, tol=Decimal('0.01')):
    issues = []
    line_sum = sum(
        Decimal(str(l['quantity'])) * Decimal(str(l['unit_price']))
        - Decimal(str(l.get('discount', 0)))
        for l in bill['lines']
    )
    subtotal = Decimal(str(bill['subtotal']))
    tax = Decimal(str(bill['tax_total']))
    total = Decimal(str(bill['total']))

    if abs(line_sum - subtotal) > tol:
        issues.append('lines do not add up to subtotal')
    if abs(subtotal + tax - total) > tol:
        issues.append('subtotal + tax does not equal total')
    if bill['invoice_date'] > today:
        issues.append('invoice date is in the future')
    if bill.get('due_date') and bill['due_date'] < bill['invoice_date']:
        issues.append('due date before invoice date')
    if partner is None:
        issues.append('vendor not found in partner records')
    elif partner.get('tax_id') != bill.get('vendor_tax_id'):
        issues.append('tax ID does not match vendor record')
    if (bill.get('vendor_tax_id'), bill['invoice_number']) in existing_keys:
        issues.append('possible duplicate bill')
    return issues

Where you have purchase orders and receipts, add a match against PO quantities and prices. Totals that reconcile are strong evidence that the numbers were read correctly. A bill that matches a PO is strong evidence that it belongs in your books.

Then measure the most important number in the whole exercise: the silent error rate. That is the share of documents that were wrong and still passed every check. Drive this toward zero before any bill skips human review.

How to improve accuracy

  1. Fix the input first. Use the embedded PDF text when it exists. Ask high-volume vendors for digital PDFs or e-invoices. Split multi-document PDFs before extraction.
  2. Write field definitions. Do not just list field names. Define them, and tell the model to return null when a value is absent.
  3. Give context. Pass your own company name and tax ID so the model knows which party is the buyer. Pass the list of known vendors.
  4. Use hybrid rules for stable vendors. For a few high-volume vendors with fixed layouts, a short vendor-specific hint or a deterministic rule can beat a general prompt.
  5. Keep arithmetic out of the model. Recompute line totals, subtotals and tax in code.
  6. Route by result. Bills that pass validation go to a quick-approve queue. Bills that fail go to a review queue that shows exactly which check failed.
  7. Close the loop. Store every human correction, add corrected documents to the test set, and rerun the evaluation on every prompt, model or rule change, just like a regression test suite.

For step 2, field definitions can live in config rather than in code:

YAML
invoice_number:
  description: The supplier's own number for this invoice. Not the PO number, order number or customer account number.
  if_missing: null
invoice_date:
  description: Date the invoice was issued. Not the delivery or due date. Return ISO format YYYY-MM-DD.
  if_missing: null
total:
  description: Final amount of this invoice including tax. Exclude previous balances and advances.
  if_missing: null

Rolling it out in accounting

  1. Shadow mode. Extract, but create nothing. Compare the output with what accounts staff key in by hand.
  2. Draft only. Create draft vendor bills in Odoo or draft purchase invoices in ERPNext, and have a person approve every one. Track how often each field gets edited.
  3. Narrow automation. Only consider skipping review for segments with no silent errors over a sustained period, a matching PO and an amount under a threshold your finance team sets.
  4. Audit trail. Store the source file, extracted values, model and prompt version, validation results and the approver for every bill.
  5. Budget. Put a hard cap on model spend so a batch of large PDFs cannot surprise you.

If you run Odoo, our Kalvyai Document Scanner scans vendor bills, customer orders and invoices into verified Odoo drafts, which fits the draft-first approach above. You can browse our other apps at store.kalvyai.com.

How Kalvyai can help

We build and connect Odoo, ERPNext and Shopify systems, and we add AI agents that work inside them with human approvals, budgets and an audit trail. For invoice extraction, that means we can help you build a ground-truth set, set up the evaluation and validation layer, map extracted data to your partners, products and taxes, and roll out in draft mode first. See our Odoo work, or contact us to talk through your vendor-bill volume and setup.

Share this article

Last updated 20 Nov 2026

  • AI invoice OCR
  • vendor bills
  • document extraction
  • accounts payable
  • Odoo
  • ERPNext
  • AI agents

Kalvyai Engineering · Engineering team

The engineers who build, connect and fix business systems at Kalvyai: Odoo, ERPNext, Shopify and AI agents that work inside them with approvals, budgets and an audit trail.

Comments

No comments yet. Questions and corrections are welcome.

Rate this post or leave a comment

Your rating (optional)
Not rated

Comments appear after an editor approves them. See our privacy notice.

Read next

WooCommerce Odoo Integration: Sync Rules, Stock, Orders, Taxes (cover)Technical
Kalvyai EngineeringOdoo

WooCommerce Odoo Integration: Sync Rules, Stock, Orders, Taxes

A practical guide to connecting WooCommerce and Odoo through the WooCommerce REST API: what to sync in which direction, how to push stock and prices, import orders safely, map taxes and avoid duplicate customers and orders.

8 min read

Tally to Odoo Migration: What to Move, Map and Check (cover)Technical
Kalvyai EngineeringOdoo

Tally to Odoo Migration: What to Move, Map and Check

A practical guide to moving from Tally to Odoo: which masters, balances, open invoices and stock to bring, what to leave in Tally, how to map ledgers and set up GST, and how to run a parallel month.

7 min read

Newsletter

Get new guides in your inbox.

Practical notes on Odoo, ERPNext, Shopify and AI agents, written by the engineers who build them. No spam, and you can ask to stop at any time.

Prefer a feed? Subscribe by RSS. We use your email only to send new articles. See our privacy policy.