
The problem
General ledger coding is the load-bearing decision in accounts-payable automation. Every invoice has to be coded to the right account before it posts; misclassified invoices show up in tax filings and in the next quarter's audit. The decision is regular by construction — the GAAP and IFRS consistency principles require companies to apply the same accounting methods consistently from period to period. Same vendor invoicing the same company in two consecutive months should hit the same GL account unless something documented has changed.
That regularity is exactly what makes the decision predictable. The same supplier × category combination almost always maps to the same GL. Yet most accounting workflows still ask an AP clerk to read the invoice, glance at the vendor history, and pick from a menu of accounts. The pattern lives in the data; the user is doing the matching by hand.
How it works
The query is a single _predict against the invoices table. Inputs: vendor, category, description, amount, customer_id (in multi-tenant deployments). Output: the predicted GL code, the top-3 alternatives, calibrated probability, and $why factor decomposition.
Automation tiers follow from the probability. The demo codes an invoice automatically at 85% confidence or above and sends the rest to review; a stricter setup auto-posts only above 95%, pre-fills and routes 50-95% to review, and leaves the field empty below 50%. The boundary moves naturally as the system accumulates more vendor history; the touchless share is whatever your history supports at the confidence you choose, and _evaluate measures it on your own invoices before you switch anything on.
{
"from": "invoices",
"where": {
"vendor": "Telia Finland Oyj",
"amount": 890.5,
"customer_id": "CUST-0000",
"category": "telecom",
"description": "Monthly mobile subscription"
},
"predict": "gl_code",
"select": [
"$p",
"$value",
{
"$why": {
"highlight": {
"posPreTag": "<mark>",
"posPostTag": "</mark>"
}
}
}
],
"limit": 50
}For the full architecture, see the technology overview. For the broader narrative across multiple use cases, read The Predictive Application.
See it live
This use case runs in the 🧾 Accounting demo today. Click through to the live application and inspect the queries that produce the result.
Frequently asked
How does this compare to OCR + rule-based AP automation?
OCR extracts the fields; predictive GL coding decides what to do with them. The two are complementary. OCR + rules typically auto-codes only on rules that you've authored manually; predictive coding handles the long tail of "this combination we haven't seen before but resembles N similar combinations" — the cases rules can't enumerate.
What happens during a chart-of-accounts reorganization?
Chart-of-accounts reorganizations cause a brief drop in account-keyed accuracy after the reorg, then recovery as the new mapping accumulates. The system reflects the new mappings immediately because there's no separate model to retrain — every override is the next prediction's training signal.
Can we audit individual GL coding predictions?
Yes. Every prediction returns $why showing the base probability, the per-feature lift factors, and the highlighted patterns that mattered. Deterministic and reproducible — the same query against the same data returns the same prediction. Auditors get a structured explanation, not a black-box score.
Will the system learn from human overrides?
Yes. When a human overrides a predicted GL, the override is the next prediction's training signal — the new row enters the index immediately. No retraining; no batch jobs; the system reflects the override in the next query against the same vendor pattern.
How accurate is GL coding at low data?
On regular accounting data a vendor's pattern stabilizes after a handful of invoices; the calibration view shows when its confidence is earned. How many invoices that takes depends on how consistent the vendor is, so measure it on your own history with _evaluate rather than assume a fixed count. On the demo's synthetic data, _evaluate gets the GL code right for 96% of 50 held-out invoices of one tenant, against a 30% base rate.



