Prompt

How do I get key-value pairs out of invoices with OCR?

Artificial Intelligence / Computer Vision1 observationLast seen Oct 11, 2026

Latest observation

Oct 11, 2026OpenAI APIWeb search: off

To extract key-value pairs from invoices with OCR, you usually need two steps:

  1. OCR text extraction
    Convert the invoice image/PDF into machine-readable text.
  2. Field extraction / key-value parsing
    Map the OCR text into structured fields like invoice_number, date, vendor_name, total, etc.

Common approaches

1) Rule-based parsing

Best if your invoices are from a few known vendors/templates.

  • Use OCR to get text
  • Search for labels like:
    • Invoice No:
    • Date:
    • Total:
  • Extract values using regex or position-based rules

Pros: simple, cheap, fast
Cons: brittle across varying invoice layouts


2) Template-based extraction

Best when invoice formats are consistent.

  • Detect layout regions
  • OCR each region
  • Associate labels with nearby values based on coordinates

This works well if you know the invoice structure in advance.


3) ML / document AI extraction

Best for many vendors and varying layouts.

Use specialized document understanding tools/models that do:

  • OCR
  • layout analysis
  • key-value extraction

Examples:

  • Amazon Textract
  • Google Document AI
  • Azure Form Recognizer / Document Intelligence
  • Open-source models like LayoutLM, Donut, or custom pipelines

Pros: handles many formats better
Cons: more setup, training, or cost


Typical pipeline

  1. Preprocess image

    • deskew
    • denoise
    • increase contrast
  2. Run OCR

    • Tesseract, PaddleOCR, EasyOCR, cloud OCR, etc.
  3. Extract text + coordinates

    • You want both the words and their bounding boxes
  4. Find labels and values

    • Example: if Invoice Number: appears, capture text to the right of it
    • If Total appears near a currency amount, pair them
  5. Normalize output

    • Convert to JSON:
    {
      "invoice_number": "INV-10293",
      "invoice_date": "2026-10-01",
      "vendor": "Acme Supplies",
      "total": "$1,245.50"
    }
    

If you’re using OCR text only

You can extract key-value pairs with regex patterns such as:

import re

text = """
Invoice No: INV-10293
Date: 2026-10-01
Total: $1,245.50
"""

invoice_no = re.search(r'Invoice\s*No[:\s]+(\S+)', text)
date = re.search(r'Date[:\s]+([0-9\-\/]+)', text)
total = re.search(r'Total[:\s]+\$?([0-9,]+\.\d{2})', text)

print({
    "invoice_number": invoice_no.group(1) if invoice_no else None,
    "date": date.group(1) if date else None,
    "total": total.group(1) if total else None
})

If you want better accuracy

Use OCR with bounding boxes. Then apply heuristics like:

  • value is to the right of the label
  • value is on the next line
  • use the nearest numeric text for totals
  • use layout-aware models for complex invoices

Recommended tools

  • Simple OCR: Tesseract, EasyOCR, PaddleOCR
  • Best out-of-the-box invoice extraction: AWS Textract, Google Document AI, Azure Document Intelligence
  • Open-source advanced: LayoutLM, Donut

If you want, I can show you:

  1. a Python example using Tesseract,
  2. a cloud API approach, or
  3. a layout-aware ML approach for invoices.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.