Engineering notes /AI architecture
AI reads, code decides
Why our compliance engine uses models to read documents but plain, tested code to reach verdicts, and where that line should sit.
Brightwave engineering · 6 min read
The most common question we get about our compliance engine is some version of: "So the AI decides whether the order is OK?" No. The AI reads the order. Plain, tested code decides whether it's OK. That split is the most important design decision in everything we build for regulated work, and it's worth explaining why.
Two different jobs
Checking a regulated order before it completes, which is the job our Order Compliance Engine does, is really two jobs.
- Reading. Pull the facts out of messy paperwork: a scanned order form, a partner's confirmation, an approval letter, an email. Prices, terms, the customer's name, the product, the signatures.
- Deciding. Compare those facts against each other, against the CRM, and against that partner's rules, and reach a verdict: match, mismatch, pending, or exception.
-
Input
Documents
Order forms, confirmations, letters, emails
-
AI
Reads
Extracts the facts, one narrow question per call
-
Data
Structured facts
Every field linked to its source
-
Code
Decides
Each partner's rules, tested and versioned
-
Person
Acts
Verdict with evidence; approve or dispute
Models are extraordinary at the first job. Documents arrive in every layout, scan quality and wording, and a model reads them the way a person does. Writing parsers for that would never end.
The second job is different. "Is the commission over the partner's cap?" has one right answer. It should give the same answer every time, for the same reason, and that reason should be something a reviewer, an auditor or a partner can read. That's what code is for.
Why not let the model decide?
It would be quicker to build. Hand the model the documents and the rules and ask for a verdict. It would even be right most of the time. Here is what you give up:
- Consistency. Ask a model the same borderline question twice and you can get two answers. A rule in code gives one.
- Explanation. A model can explain its verdict, but the explanation is generated after the fact. A coded rule is the explanation: "term on the order (36 months) does not match the partner confirmation (24 months)".
- Testing. You can write a test for a rule and run it on every change. Testing a prompt's judgement means sampling and hoping.
- Change control. When a partner changes a cap, a developer changes one number, a test proves it, and the change is reviewed. Changing a prompt changes behaviour in ways nobody can fully enumerate.
If a decision moves money or affects a customer, someone will eventually ask why it was made. "The model thought so" is not an answer anyone wants to give.
Where the line actually sits
The rule isn't "no AI judgement ever". Some comparisons are genuinely fuzzy. Is "Acme Holdings Ltd" on the contract the same company as "ACME HOLDINGS LIMITED" in the CRM? Is this the same product described two ways? A model is the right tool for those, and we use one.
The discipline is to keep those judgements:
- Narrow. One small, well-defined question per call, never "is this order OK?"
- Labelled. The verdict shows which findings came from a rule and which from an AI comparison, so a reviewer knows where to look harder.
- Overridable. A person can disagree with any finding, and that disagreement is recorded.
Reviewers make it better over time
The reviewer rates every finding in the tool. That feedback goes to the right place depending on where the finding came from. A wrong reading means a prompt or extraction problem, fixed and re-tested against a set of real documents. A wrong rule means a code change, with a test. A disputed AI comparison becomes a new example for that narrow judgement.
Because the reading and deciding are separate, you always know which part to fix, and a fix in one can't quietly break the other.
The tool reports. People act.
The last part of the design is the simplest: the tool never acts on its own verdict. It doesn't release an order, reject a deal, or contact a customer. It tells a reviewer what it found and shows the evidence, in under a minute instead of half an hour, and the reviewer decides.
That's what makes it safe to automate work like this at all. AI takes the slow reading off people's desks. Code makes the checks the same every time. People keep the decisions that matter.