Prompt

How do I extract line items from invoices and receipts?

Technology / Data Infrastructure1 observationLast seen Oct 11, 2026

Latest observation

Oct 11, 2026OpenAI APIWeb search: off

To extract line items from invoices and receipts, you typically use a mix of OCR, document structure detection, and table/line-item parsing.

Common approach

  1. Input the document

    • PDF, scanned image, photo, email attachment, etc.
  2. Run OCR

    • Convert the image/PDF text into machine-readable text.
    • Good OCR tools also return bounding boxes for each word/line.
  3. Detect layout

    • Identify regions such as:
      • header
      • vendor info
      • total/subtotal/tax
      • line-item table
    • This helps separate item rows from the rest of the document.
  4. Extract line items

    • For invoices, line items are often in tables with columns like:
      • description
      • quantity
      • unit price
      • amount
    • For receipts, line items may be more free-form, so you may need heuristics or an ML model.
  5. Post-process

    • Normalize currency, quantities, dates
    • Merge broken lines
    • Validate totals against subtotal/tax/total

Methods you can use

1. Rules-based parsing

Best when invoice formats are consistent.

  • Use OCR text and regexes to find table-like sections
  • Detect rows using spacing or alignment
  • Extract columns based on positions

Pros: simple, fast
Cons: fragile across different layouts


2. Template-based extraction

Best when you receive documents from a limited set of vendors.

  • Build a parser for each invoice template
  • Use coordinates to extract known fields and line items

Pros: high accuracy for known formats
Cons: doesn’t scale well to many vendors


3. ML / Document AI models

Best for many different invoice/receipt formats.

  • Use document understanding models that combine OCR + layout + NLP
  • Examples:
    • Google Document AI
    • AWS Textract
    • Azure Document Intelligence
    • open-source models like LayoutLM-based pipelines

Pros: works across varied layouts
Cons: more setup, cost, training/tuning may be needed


4. LLM-assisted extraction

Useful when line items are messy or OCR output is imperfect.

  • Feed OCR text plus layout info to an LLM
  • Ask it to return structured JSON
  • Use strict schema validation afterward

Pros: flexible
Cons: must guard against hallucinations; validate carefully


What a line item schema might look like

{
  "description": "Widget A",
  "quantity": 2,
  "unit_price": 5.00,
  "amount": 10.00
}

For receipts, you might only reliably get:

{
  "description": "Coffee",
  "amount": 4.75
}

Practical tips

  • Use OCR with coordinates, not plain text alone, if possible
  • Preserve line breaks and spacing
  • Handle multi-line descriptions
  • Watch for totals that appear in the line-item area
  • Verify extracted amounts against subtotal/total
  • Use confidence scores and fallback logic for uncertain rows

Example workflow

If you want something production-ready:

  1. Upload invoice/receipt image or PDF
  2. OCR it with layout output
  3. Detect the line-item table region
  4. Parse rows into structured fields
  5. Validate totals
  6. Return JSON

If you want to build it yourself

A basic Python pipeline might use:

  • pytesseract or easyocr for OCR
  • pdfplumber for text-based PDFs
  • opencv for image preprocessing
  • regex + heuristics for row extraction
  • optional LLM for cleanup/structuring

If you want, I can show you:

  1. a Python example for extracting line items,
  2. a recommended API/tool stack, or
  3. how to do it for scanned PDFs specifically.

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.