Testing AI answers without calling a model
Put every figure behind a deterministic engine, then test it with no model: invariants every answer must keep and known questions graded against source.
Put every figure behind a deterministic engine, then test it with no model: invariants every answer must keep and known questions graded against source.
Test AI like software: real cases, code checks for what must hold, a calibrated LLM judge for the rest, human audits, and a release gate on every change.
An agent plans the query; a Rust engine with no model computes each figure and returns a certificate tracing it to the records, checking access on every read.
A recurring report. A slow review. A prototype that needs to work in the real world.
You can regression-test most of an AI system's numbers without calling a model at all. Split the work so the model decides which questions to ask and how to phrase the reply, while a deterministic engine computes every figure. Then test that engine directly through the same interface the agent calls, checking properties every answer must hold alongside known questions graded against truth worked out from the source systems. Each run is cheap, fast and repeatable on the same data, leaving model calls for the thin layer that actually needs them.
In our earlier guide on evaluating AI systems at scale, we argued for making every check deterministic wherever you can. Below is how we run that in practice for the analytics agents in the Company Twin, including the faults it caught that a model-graded eval would have walked straight past.
Key takeaways
In the Twin, figures come from a Rust graph engine that holds an organisation's semantic model and synced data in memory. It calls no model. Every table it returns carries a certificate showing when its data was read, and any figure traces back to the records behind it. The task agent plans the queries and writes the answer; it never touches the arithmetic.
That split turns one awkward question ("is the agent right?") into two manageable ones. Is the number right? That's an engine question with a deterministic answer. Did the agent ask for the right number and state it cleanly? That needs a model, and it's a much smaller surface. Testing both together through full agent sessions is slow, burns model calls on every run, varies from run to run and can't tell you which half broke.
The practical trick is hitting the engine through the exact same interface the agent uses. The Twin CLI exposes the structured queries an agent writes, so a test is just a query and a comparison:
# How many sales invoices are overdue? The same query the agent would send.twin graph query '{"measures":["invoice_count"], "where":[{"field":"invoice_type","op":"eq","value":"ACCREC"}, {"field":"status","op":"eq","value":"AUTHORISED"}, {"field":"due_date","op":"lt","value":"2026-11-11"}]}' --json # The answer comes back as a table with its certificate: no model was called.Our answer suite started as a day of hand-built known-answer tests. Engineers listed the records behind about 130 questions across four organisations, worked out each answer, and ran them the way an agent would. They turned up faults a demo would never expose: money out that missed paid bills, credit notes that mixed customers and suppliers, operating expenses that included tax, and deal stages nobody could read. All of them were fixed in the engine and its models.
Those first tests only ran once, from scratch files, and most took their truth from the graph itself, so they couldn't catch rows dropped on the way in, a stale sync or a bug shared by both paths. The standing suite keeps the questions and gives them independent truth. Each test lives in target configuration: a question in the business's own words, the queries an agent would send, which measure holds the answer, a tolerance, and how to work out the truth at run time.
{ "id": "overdue-sales-invoices-count", "question": "How many sales invoices are overdue?", "category": "receivables", "ask": [{ "measures": ["invoice_count"], "where": [ ... , { "field": "due_date", "op": "lt", "value": "{today}" }] }], "answer": { "query": 0, "measure": "invoice_count" }, "truth": { "kind": "sql", "sql": "SELECT count(*) AS invoice_count FROM ... WHERE ... due_date < {today}" }, "tolerance": 0}Relative dates like {today} and {last_month.to} keep tests current without manual edits. Anything that would name a person, a customer's own term or an amount sits behind a placeholder filled from a local file at run time, so the test definition names nobody and holds no figures. Truth comes from the strongest source available:
| Truth | How it is worked out |
|---|---|
| Report | The source system's own report, such as the ledger's P&L or aged receivables |
| Source | A figure read from the source system's API by an operator into the run's parameters |
| SQL | One read-only SELECT over the tenant's own tables, run on its server at test time |
| Query | Another graph query that must agree, such as receivables against the control account |
| Listing | The records listed by id, filtered and summed: the last resort |
| Pending | No truth yet: the queries run and are logged, but nothing is graded |
SQL truths run inside a read-only transaction with a 60-second limit. Because the database is read live while the graph reflects its last refresh, a mismatch triggers one retry of both readings before failing. An SQL-truth test reports loudly without gating a release on its own, which stops a transient comparison hiccup from blocking a fix.
Two small habits paid off early. Our first SQL truth passed, and the same query with one sign flipped failed, which is how you know a test can actually go red. We also write deliberate traps: cases where the obvious query an agent would try gives the wrong answer, such as a city filter that misses values written as "City, ST". A trap passes while the obvious query still misfires and fails the day it starts working, signalling that the trap has gone and the test should be updated.
An answer suite only catches what someone thought to ask. Invariants cover the rest. An invariant is a property every answer has to keep in every organisation regardless of its data, tested by asking the engine the same question two different ways and checking that they agree. The idea is old (it's what property-based testing and metamorphic testing formalise); what's new is running it across every measure an AI agent can quote.
| Invariant | Holds |
|---|---|
| Groups | The groups of a grouped figure add up to the ungrouped figure, blank key included |
| Periods | The two halves of a year add up to the year for a flow; a snapshot reads one date and says which |
| Partition | A filter on one value and its negation add up to everything, as do null and not null |
| Distinct | A distinct count is never more than the entity's rows |
| Currency | A figure over several currencies is refused, naming them; with one currency it answers |
| Order | The top five are the first five of the full ordering, and a cut table says rows were left out |
| Links | Following a chain of links counts what the two-step query counts |
| Grain total | A flow by year adds up to its total row, or says what it left out |
| Empty cause | An answer emptied by a condition names the condition |
The checks generate straight from each organisation's catalogue and run over every measure in it, so a new measure, a new model or an engine release gets covered without anyone writing a new test. The first runs caught three faults. The very next day, a coding agent set loose to probe the engine by asking one thing two ways found 24 more: time groups falling short of their total, hour windows read as whole days, empty answers with no explanation, retired measures answered as if they still existed, and sums across currencies. Each probe became a standing invariant, so the next run proves the fix stayed fixed.
Both suites run after each release lands in production and after every change to an organisation's semantic model. They aren't automatic yet: the agent session that shipped the release or model change kicks them off. Both are read-only, model-free and go through the same CLI as everyone else, each call pinned to its organisation and capped at one call per second. Up to six queries travel in a single call so a check's two readings see the same data; if the underlying data shifts mid-check anyway, the check retries once and skips if it moves again. Running across every organisation takes minutes.
Because results contain an organisation's real figures, they stay where the run happened. Only pass and fail counts reach the shared task board our team and agents use, and any failure is filed with the invariant, the measure and the query shape (no values, figures or names). Part of the suite also runs in CI straight against the model files, rejecting things like a measure over monetary amounts on an entity that declares no currency field.
At the top of the pyramid, and only there. Only a real agent run can show whether an agent picks the right measure, asks a sensible follow-up, refuses a question it should refuse and states a figure without garbling it. We keep those runs capped to a handful of sessions per validation, strictly after the model-free checks go green.
Code grades those sessions rather than another model. An answer grader reads the agent's final text and checks every expected fact against the same run-time truth: within tolerance or the answer's own stated rounding, in the right currency, in the right order for a ranking, with an itemisation that adds up to its total. A contradiction fails the answer; a missing fact marks it inconclusive, never correct. A judge model is handy for tone and helpfulness, as our earlier piece covers, and it's the wrong tool for checking whether a number matches the ledger.
One lesson from building a reproducible task benchmark for our own models is worth repeating. Its first version graded only the final answer, which let a correct figure reached by unauthorised SQL or by reading the wrong organisation pass. Version two grades the path as well: what was in scope, what each step returned and what it did. Six unchanged runs reproduced identical metrics, and review caught two currency-grading bugs in the grader itself. Test your grader as hard as the system it grades. Our product team's take on the same principle is in a skill is a hypothesis.
A starter set of invariants for any analytics agent
Start by locating the deterministic core of your AI system: the SQL, semantic layer, calculation service or API that actually produces the figures. If the model is doing arithmetic itself or writing free-form SQL against your warehouse, move that behind a governed interface first; the five controls in five gates to a governed answer set out the target. Then:
In our experience, the first two steps turn up more real faults in a week than months of reading model transcripts, and they keep catching them after every change.
Every number a Twin agent quotes comes out of the Rust graph engine, tested model-free after every release. See how the Twin certifies figures →