Architecture and technical rescue ·Build
Should this process be an AI agent? The model proposes, the code decides
A personal order-capture demo and quoting module
A model belongs in the step that reads unstructured input and never in the step that writes to the ledger. The proposal that usually arrives is the opposite: an agent that reads the document, decides what it means and posts it. Analysts expect a large share of agent projects to be cancelled by the end of 2027, citing cost, unclear value and weak risk controls.
I built the alternative for orders and supplier invoices: a workflow whose steps are code, with the model confined to reading, and a review queue for whatever it is unsure of. On 36 labelled documents, 13 were posted with nobody involved, exactly the 13 the rule predicted, and none that needed review was posted.
- Problem
- a business wants orders and supplier invoices handled without people retyping them, and fears a wrong posting in the ERP, a result nobody can explain, and a pilot that never leaves the pilot stage.
- Deciding constraint
- nothing reaches the business system on a model's word alone, and the process must keep working, more slowly, when the model is wrong or unavailable.
- Choice
- a workflow whose steps are code, with the model confined to the step that reads unstructured input, and a review queue for what it is unsure of.
- Result
- on a labelled set of 36 documents, 13 were posted with no person involved, exactly the 13 the criterion predicted, and none that needed review was posted. Every scan went to a person. The model can be changed, measured or removed without redesigning the process.
If this is your situation
If someone proposes an agent for a process you can already draw as steps, draw the steps first and mark the places that really need a model. Usually there are few. An agent is justified where the path cannot be written down, and even there the rules of the access article apply.
Applied AI → discuss where the model goes
For your technical team How it was diagnosed, the options rejected and why, what went wrong, and the decision record.
Context and scope
The setting is a finance or sales-admin team that receives orders and supplier invoices as PDFs and emails, in layouts nobody controls, and posts them to an ERP. In scope: one process with documents in and an ERP out. Out of scope: assistants that answer questions over company data (a different problem, about access rather than process), and training or fine-tuning models.
Drivers
Constraints
- A small team operates it, with no machine-learning specialist.
- Documents arrive in layouts and languages nobody controls.
- Anything posted to the ERP must be explainable afterwards.
- Personal data in the documents limits where a model may run.
Scenarios
- When the model reads a field with low confidence, the document goes to a person and nothing is posted. Measured by the share of documents routed to review on a labelled set.
- When the model or its prompt changes, a set of known documents is read again and the change is refused if accuracy falls below the agreed threshold. Measured by the regression run on every change.
- When the model is unavailable, documents wait and nothing is lost or posted twice. Measured by stopping the model and replaying the queue.
- When the same document arrives twice, one posting results. Measured by sending it twice.
Options against those drivers
| Model | Who decides | Explainability | Cost per document | When it fails | Change |
|---|---|---|---|---|---|
| Agent | The model, at runtime | A trace, after the fact | Variable, grows with steps | A wrong step can cascade | A new model or prompt shifts behaviour everywhere |
| Workflow with model steps | The code; the model only reads | Each step recorded | Bounded: a model call per document | Contained to one step | Read the known set again |
| Rules only | The code | Complete | Lowest | Rejects what it cannot parse | A new layout needs a new rule |
The decision and how it works
The rule is that the model proposes and the code decides. Five invariants support it.
The model produces data, never actions: field values with a confidence, nothing that can call the ERP. Every value passes rules before it counts: totals add up, tax identifiers check, the supplier exists. Below the threshold, or when a rule fails, a person decides, and the correction is kept so that a correction that repeats can become a rule. Posting is deterministic and idempotent, and the model never computes a price or a total. The progress of each document is stored outside the model: in the demo, a status column that one state machine alone may write, and jobs as rows a single worker claims in one atomic statement, so a restart, or a wait for a person that lasts days, loses nothing. A workflow engine is worth adding when waits are long or steps span systems; below that, a job table and a status are enough.
What the demo measured
The demo reads customer orders and supplier invoices into an ERP, built against a published ERP API and running against a mock of it, on 36 generated documents with a ground-truth manifest. The model runs locally. Figures from the run of 23 October 2026.
| Measured on the labelled set | Result |
|---|---|
| Values read correctly, PDFs with a text layer (24 documents) | 100% |
| Values read correctly, orders written in an email (5) | 99.2% |
| Values read correctly, scans and photos (7) | 95.6%, and every one went to review |
| All values (1,449) | 99.1% |
| Order lines matched to the right article | 99.5% (181 of 182) |
| Posted without review | 13 of 36, exactly the 13 the criterion predicted |
| Posted without review when review was required | 0 |
A document is posted automatically only when every field is high-confidence, every check passes, the customer is found by tax number and every line matches an article by alias, code or barcode, never by similarity. That is why the scans, misread far more often than text, cost a person's time but never a wrong posting.
The quoting module draws the same line more sharply. A request in the customer's words is read into option values (format, pages, quantity, binding), and that is all the model does: it never sees the rates and never produces a price. A deterministic engine refuses an impossible combination with its reason (saddle stitching 128 pages) and prices a possible one from the client's own rates, step by step; a person approves; only then is the quote posted to the ERP and read back. 141 tests cover it, seven of them property-style over thousands of generated jobs.
Where the model runs
The data tier decides first. Documents with personal data stay on a local model, or go to a hosted one only under a processing agreement that names the vendor; special-category data never leaves local infrastructure. Inside what the tier allows, the choice is made on measurements for this task: the same labelled set through each candidate, accuracy per field, time and cost per document, dated. Model versions change quickly, so the comparison is a dated result for this corpus, not a ranking.
How the decision is kept true
Agree the criteria before building: which fields matter, how accurate each must be, and what a wrong value costs. Keep a labelled set of known documents, including awkward ones. The threshold that sends a document to review is a trade: raise it and more work goes to people, lower it and more errors reach the ERP. A regression run refuses any change to the model, the prompt or the rules that lowers accuracy below the agreed level. In production a person re-checks a sample of the documents that were accepted automatically, and the share routed to review is watched over time. The same discipline guards the access rules of an assistant: a test that fails when the decision stops holding.
A set generated by the author flatters the result. Real documents change the figures, so a first engagement starts by labelling a sample of the client's own.
Reading the record, not the code
With an agent the path is decided at runtime, so what happened can only be read from a trace. A workflow keeps its path in code, but the model step still needs a record per document: a reference to the input, the model and prompt version, the output with its confidence, the rule results, who reviewed it and what was posted. That record answers "why was this posted?" without running anything again, and it is the same audit idea as the log of an assistant's calls.
Where this usually goes wrong
| Risk | Likelihood | Impact | Mitigation | Owner |
|---|---|---|---|---|
| A confident wrong value passes the rules | Medium | A wrong posting | Cross-field rules, a sample of accepted documents, reconciliation | Architect |
| The threshold is set once and never revisited | High | The queue is empty or overloaded | Watch the share routed to review | Operator |
| The model or prompt changes without a re-run | Medium | A silent drop in accuracy | The regression run on every change | Developer |
| The review queue is not worked | High if volume grows | Documents stall | Queue age on a dashboard, an owner for the queue | Operator |
| Retries multiply the cost per document | Medium | The budget | Cap calls per document; record the cost per document | Developer |
| Text in a document steers the model | Medium | Wrong values, but no action is possible | The output is data checked by rules and cannot call anything | Architect |
Operations, cost and scale boundary
- To run: the queue, the model endpoint (local or hosted), the labelled set and the regression run.
- To learn: the thresholds, and what a correction should turn into.
- Cost: per document, known after the first labelled run; in the demo, on a laptop GPU with 6 GB, a median of 30 s per text document and 3 to 10 minutes per scan or photo.
- Tested range: 36 generated documents.
On a different stack
Nothing above depends on a language. A queue and a table, or a workflow engine, hold the state; the model is one call behind an interface; rules are code.
Applied AI → discuss where the model goes