Invoice Line Matching

Supplier invoice lines matched to the catalog SKU they refer to: _predict of sku across the link to products returns a ranked shortlist with reasons, scored live against held-out truth.

Invoice Line Matching: screenshot from the ERP demo
📋 ERP_predict_searchERPAccounting
In the demoThe ERP demo's Invoice Matching on the Retail profile: each line gets a ranked SKU shortlist with reasons, marked right or wrong against held-out truth, with new suppliers flagged as cold. Measured on 2,000 held-out lines against 3,200 catalogue SKUs: 89.2% top-1 and 97.1% top-5 (Aito 2.11.2).

The problem

Supplier invoices describe items in the supplier's words, not the buyer's catalog codes. Before a line can be matched to a PO or posted to inventory, someone maps it to a SKU, and with thousands of SKUs that mapping is a daily chore.

How it works

The invoice line's fields, including its vendor, go into the where clause and _predict of sku follows the link from invoice lines to the product catalog. The answer is a ranked shortlist with the reasons behind each candidate, so a reviewer confirms the right SKU instead of searching for it.

The demo runs a live batch against held-out lines and marks each prediction right or wrong, so the accuracy on view is measured, not claimed. Lines from suppliers with no history are flagged as cold.

{
  "from": "invoice_lines",
  "where": {
    "description": "Tikkurila Cush 45cm Blac Pro kouvola",
    "billing_supplier": "Frontier Goods Ltd",
    "unit_of_measure": "ea",
    "unit_price_eur": 37.19,
    "quantity": 2,
    "billing_supplier.city": "Helsinki",
    "billing_supplier.position": "importer",
    "billing_supplier.sells_origin": "Tallinn",
    "billing_supplier.sells_grade": "budget"
  },
  "predict": "sku",
  "select": [
    "$p",
    "$value",
    {
      "$why": {
        "highlight": {
          "posPreTag": "«",
          "posPostTag": "»"
        }
      }
    },
    "name",
    "category",
    "supplier",
    "unit_price",
    "unit_of_measure"
  ],
  "limit": 5,
  "config": {
    "ai": "and"
  },
  "basedOn": [
    "name",
    "supplier"
  ]
}

For the full architecture, see the technology overview. For the broader narrative across multiple use cases, read The Predictive Application. For the whole picture, see predictive ERP.

See it live

This use case runs in the 📋 ERP demo today. Click through to the live application and inspect the queries that produce the result.

Open the live demo →

Build it with Claude Code

Paste this prompt into Claude Code, or another coding agent, in your own codebase. It runs Aito locally from the Docker image, reads the API docs written for agents, and follows a working reference implementation.

Invoice line matching: a prompt for Claude Code
Add invoice line matching to this codebase using Aito, a predictive database. The feature: match each incoming invoice line to the purchase-order line it bills, with a confidence, and flag the ones that don't fit.

1. Run Aito locally: `docker pull ghcr.io/aitohq/aito`, then follow https://aito.ai/docker/ to start it with your own API keys (keep them in the environment, never in code).
2. Read https://aito.ai/docs/api/llms.txt for the v2 query shapes before writing any query.
3. Read the use-case guide: https://aito.ai/use-cases/invoice-line-matching/
4. Use this reference implementation as the pattern (schema, data load and queries): https://github.com/AitoDotAI/aito-erp-demo/blob/main/src/matching_service.py and https://github.com/AitoDotAI/aito-erp-demo/blob/main/src/match_eval.py
5. Find the matching tables in this codebase, design the Aito schema for them (links between tables where we have foreign keys), and load a sample.
6. Measure before wiring the UI: hold out recent rows, run the predictions, and report accuracy against the current behaviour.
7. In the UI, show the confidence ($p) and the reasons ($why). Fill in automatically only above a threshold I choose; below it, suggest.

Ask me before changing anything outside the new feature.