Categorized spend you can trust
How a rules-first engine sorted millions of invoice lines into a five-level spend taxonomy, scored every line's confidence and sent only the uncertain ones to a person
Summary
Almost every procurement initiative starts with the same question: "What are we actually buying?" The answer is usually buried in ERP extracts whose category codes are too coarse, too inconsistent or simply missing.
Over a series of engagements with health systems and a public university, a spend categorization engine was built that classifies every transaction line into a five-level taxonomy, assigns a confidence score, and sends only the uncertain lines to a person. The engine is driven by configuration files rather than code changes, so it can be set up for a new client's data in hours.
- Scale: in the largest deployment the engine classified more than 6 million invoice lines worth over $10 billion and auto-accepted 91.6% of spend.
- Measured accuracy: on the share of lines that carry an independent vendor product code, agreement with that code was above 99%.
- Honest review flags: agreement was 99.99% within Auto-Accept but only 73.2% within Quick Review, so the review flags point at genuinely uncertain lines rather than at random ones.
- Rules before inference: where a client's codes already carried meaning, plain mapping was faster, cheaper, fully explainable and more accurate than embeddings.
1. Why spend data resists categorization
Procurement and finance leaders need spend grouped in a way that supports decisions: how much goes to surgical supplies, to facilities maintenance, to consulting. The source systems rarely provide that view.
The cost of getting this wrong is real: savings opportunities are sized against the wrong base, supplier consolidation targets the wrong categories, and leaders lose confidence in the numbers.
- Codes are too coarse. ERP spend categories often lump very different purchases together: a single "contracted services" code can cover legal counsel and janitorial work. In one academic medical center, a few dozen of several hundred category codes were ambiguous in this way.
- Descriptions are thin. The free-text field that might rescue a coarse code is often empty; in that same client's data, the line memo was blank on most rows.
- Volumes rule out manual work. One pediatric academic medical center had hundreds of thousands of transactions; a large multi-hospital system had more than 8 million raw invoice lines over three and a half years.
- Extracts carry hidden defects. In the largest dataset, about a quarter of raw rows were exact duplicates created by the export query, inflating reported spend by roughly $145 million before they were removed.
- Every client is different. Column names, code schemes, taxonomies and ERP platforms change from one engagement to the next, so tools built for one client tend to be rewritten for the next.
The cost of getting this wrong is real: savings opportunities are sized against the wrong base, supplier consolidation targets the wrong categories, and leaders lose confidence in the numbers.
2. Strongest evidence first, uncertainty in plain view
The engine runs a waterfall of classification tiers. Deterministic signals, such as a known category code that maps cleanly to the taxonomy, are applied first. Weaker signals (supplier name patterns, keywords, cost center, line of service) are used only for the lines the earlier tiers could not settle. A final pass corrects known mismatches, for example a medical equipment maker whose repairs were coded as facilities spend.
Everything that varies by client lives in configuration, apart from the engine: column mappings, the code-to-taxonomy map, supplier and keyword rules, confidence thresholds and the reports to produce. Adding a client means writing those files, not changing the program, and onboarding is estimated at two to four hours before rule tuning. Taxonomies differ from one client to the next; the companion essay, Spend categorization is a governance choice, looks at that decision.
Uncertainty is never hidden. Every line carries its taxonomy path, the method that classified it and a confidence score, and is sorted into Auto-Accept, Quick Review or Manual Review. Reviewers see a short, focused queue instead of the whole dataset.
Coverage is not accuracy, so accuracy is measured and then guarded. Where part of the data carries an independent code (for example a UNSPSC code supplied by vendors), that code is used as a check on the engine's answers, and a stratified, dollar-weighted sample can be hand-labelled to measure accuracy on the rest. Once results are accepted, they are frozen as baselines so that later data refreshes cannot drift silently.
The method is chosen to fit the data. Where descriptions are rich and codes absent, text matching and embeddings help; where the ERP codes already carry domain knowledge, deterministic mapping beats inference. The engine evolved to support both.
3. How a run works
From the analyst's point of view, a run has five steps:
- Prepare the extract. Raw files are consolidated, duplicates removed and a classification key derived for each line (for example a vendor-supplied product family when present, else a standard product code, else the general-ledger description).
- Configure. The client's configuration names the columns, points to the mapping and rule files, and sets the confidence thresholds.
- Classify. The waterfall assigns each line to the taxonomy. A typical sequence is code mapping, supplier refinement, keyword rules, context refinement, cost-center refinement, a low-confidence fallback for whatever remains, and a final supplier override. Each line then lands in Auto-Accept, Quick Review or Manual Review according to its confidence.
- Review. Quick Review and Manual Review lines are exported for analysts. Recurring patterns in the queue become new rules, and the waterfall is run again until the review share is small.
- Deliver. The client receives a workbook (or data files for very large datasets) with every line classified, plus summaries by category level, cost center, facility or any other configured dimension, and drift checks on each refresh.
The engine is a Python command-line tool that scales to millions of rows on an ordinary workstation and needs no network access. In the largest deployment a single command produces the full set of deliverables in about 25 minutes, and unchanged years can be skipped on a re-run. The automated regression suite has grown to more than 180 tests, including one that checks that repeated runs give identical results line for line. Three drift checks (categorization totals, spend segmentation and measured accuracy) stop a refresh if results move beyond agreed tolerances.
4. How the method changed with each client
The engine is the result of several engagements, each of which changed the design:
- An academic health system. A hybrid of more than 200 keyword rules and a fine-tuned sentence-embedding model: rules classified 87.1% of lines and embeddings the remaining 12.9%. An automated "auto-fix loop" detected attractor categories (categories the model overused), generated corrective rules and re-ran until the results converged. A companion tool mapped several thousand lines to UNSPSC codes and the healthcare taxonomy, with full UNSPSC coverage and 96.9% coverage at the third taxonomy level.
- A pediatric academic medical center. Embeddings were dropped deliberately. The client's ERP category codes already encoded most of the meaning, so a deterministic seven-tier waterfall replaced them, and code mapping alone settled 90.6% of rows. To clear the remaining queue, AI research agents examined the top suppliers by spend, first by name alone and then, for the ambiguous ones, with web research; the findings were validated and turned into supplier rules.
- A public university. A different shape of data: rich descriptions, weak codes. A four-layer cascade (vendor rules, description keywords, fuzzy matching, account rules) used several hundred rules in all and suggests UNSPSC codes for each category. A web version added file upload, rule management without editing files, rule-usage analytics and a natural-language assistant for questions about the categorized spend.
- Generalization. The healthcare and higher-education approaches were combined into one engine with pluggable matchers (code maps, code-to-taxonomy lookup, segment fallback, vendor, keyword, fuzzy and account matching) and industry profiles that set the order in which they run.
- A multi-hospital health system. The configuration-driven engine was hardened for scale, auditability and repeat refreshes.
5. What the deployments delivered
| Client | Data classified | Result |
|---|---|---|
| Multi-hospital health system | More than 6 million invoice lines, over $10 billion | 91.6% of spend auto-accepted |
| Pediatric academic medical center | Hundreds of thousands of transactions, billions of dollars | 99.7% of transactions auto-accepted, the remainder flagged for quick review |
| Public university | Tens of thousands of transactions, several hundred million dollars | 100% match rate |
| Academic health system | A few thousand transactions | Average confidence of 0.86 |
These figures describe different datasets with different signal quality, so they should not be compared directly. They show that the same method reaches high automated coverage on very different inputs, and that accuracy can be measured rather than assumed.
The reference deployment
The multi-hospital health system is the current reference deployment: more than 6 million unique invoice lines and over $10 billion of spend over three and a half years, after removing about 2 million duplicate rows from the raw extract. Accuracy was checked on the roughly 22% of lines that carry an independent vendor product code, where top-level category agreement was 99.35% overall.
| Review tier | Share of spend | Top-level agreement with vendor product code |
|---|---|---|
| Auto-Accept | 91.6% | 99.99% |
| Quick Review | 3.1% | 73.2% |
| Manual Review | 5.3% | — |
The review flags point at genuinely uncertain lines rather than at random ones. Before a round of mapping refinement, Auto-Accept stood at 75.6%; the refinement moved spend from review to Auto-Accept with no loss of measured accuracy.
Spend was segmented into operational (sourceable) spend, capital, physician and affiliation payments, and accounting entries, so that savings work targets the addressable base: $8.9 billion, or 67% of the total. A separate, client-agnostic version of the engine reproduced these results on the full dataset (99.38% proxy accuracy against 99.35%, 99.91% of dollars landing on exactly the same category) in 96 seconds. It is now the starting point for new engagements.
6. Where this applies
- Health systems and academic medical centers with large accounts payable and procurement extracts, especially those preparing for GPO reviews, tail-spend programs or supplier consolidation.
- Universities and public institutions whose spend is coded by account rather than commodity.
- Any organization moving to a standard taxonomy (UNSPSC or a custom hierarchy), or merging data from several ERPs after an acquisition.
- Ongoing spend visibility programs that need the same categorization refreshed monthly or quarterly without results shifting unexpectedly.
7. Lessons for another team
- Deterministic first, AI where it earns its place. Embeddings and language models were valuable when descriptions were the only signal, and for researching unfamiliar suppliers. Where the client's codes already carried meaning, plain mapping was faster, cheaper, fully explainable and more accurate.
- Coverage numbers flatter; accuracy numbers inform. A 100% classified rate says nothing about correctness. An independent proxy and a labelled sample turned "everything has a category" into a measured answer to how often the category is right, and where it is not.
- Clean the extract before classifying it. The largest dataset contained a quarter duplicate rows from the export itself. Duplicate checks and guards against partial data drops now run before any classification.
- Freeze results once they are accepted. Drift checks that stop a refresh when totals or accuracy move have prevented silent regressions as new data and new rules arrive.