Certified answers from a Rust graph engine
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.
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.
Use classic RAG when the evidence sits in one place; add an agent loop when it is spread across documents or needs tools. Most systems route between the two.
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.
A recurring report. A slow review. A prototype that needs to work in the real world.
If you want to stop an AI agent inventing numbers, take the arithmetic away from it. In the Company Twin, the agent plans a structured query and writes the explanation, while every figure is computed by a deterministic graph engine in Rust that calls no model at all. Each result comes back with a machine-checkable certificate pinning the query, the definitions, the versions of the model and data, and a hash of the table, so anyone can rerun it and get the exact same answer, or trace any cell straight back to the source records behind it.
Splitting planning from counting solved the failure mode that quietly ruins text-to-SQL in production. Getting there meant putting an organisation's semantic model into memory, enforcing access before a row is ever read, refusing cleanly when the model has a gap, and stripping per-row allocations out of the hot loop.
Key takeaways
The usual way to let a language model answer "what did we invoice in Q3?" is to hand it a schema and let it write SQL. That looks great in demos and fails quietly in production, because you're asking the model to make two different kinds of decision at once. Deciding what to ask is a language problem, and models are good at it. Deciding how to compute the figure (which table holds the truth, whether a credit note nets against an invoice, whether two currencies can be added, whether a balance is summed or read at a date) is a set of business rules. A model that gets those right nine times in ten is wrong often enough to lose a finance team's trust for good.
We've written before about guarding model-written SQL. Guards help, though they only fence in the arithmetic rather than replacing it. The graph engine moves those rules out of the prompt and into code that's tested once and applied every time.
The task agent reads a catalogue of what the organisation's graph can answer: entities, their dimensions and links, and named measures with descriptions. For any question it writes up to six structured queries, each naming measures, grouping dimensions, filters and a time window. It never writes SQL and never totals a column itself. The engine executes the queries and returns tables; the agent writes the prose around them, citing the certificates.
The planning step never reads the whole graph. For each question the engine builds a short brief: the names the question mentions and the 16 most relevant measures, ranked by BM25 (a standard keyword-relevance score that favours rarer words shared with the question) over their names and descriptions. We tried ranking by meaning with embeddings and dropped it, because plain words did the job just as well and cost less to run (the trade-off is the one in our guide to embeddings). Over 446 measures the brief takes about 8 ms.
A query, as the agent writes it, looks like this:
{ "measures": ["invoice_amount_total"], "by": ["currency"], "where": [{ "field": "status", "op": "in", "value": ["PAID", "AUTHORISED"] }], "time": { "from": "2026-07-01", "to": "2026-09-30" }, "totals": true}Each organisation has one declared semantic model, loaded into memory. Its baseline comes from the governed warehouse views our connectors maintain: one entity per view, with typed fields, keys, relationships as links, dates, and money columns as totals. An organisation can also maintain its own model with richer entities, matching rules and measures, kept under version control and reported by hash so we always know which definitions produced a figure. On top of either, every model gains:
The service itself is small, conventional Rust: axum for HTTP, tokio-postgres and tiberius for the two database dialects, zstd for snapshots on disk. It listens only on loopback and answers only the tenant API, which holds its credential. The executor running agents holds neither its address nor its secret.
Most of the value sits in the rules that govern each figure, because they're the exact rules a language model tends to slip on:
| Rule | What the engine does |
|---|---|
| Currencies are never added | A sum over amounts in several currencies is refused, naming them, until the query groups or filters by currency. |
| A balance is read at a date | A snapshot measure such as closing cash reads the latest date in each period; adding a balance across months is refused or flagged. |
| A period needs a time rule | A window on a measure with no date to apply it to is refused, naming the dates it could use, instead of answering the all-time figure. |
| A count of nothing is zero, with a reason | An empty answer says why: which filter or window removed the rows. |
| Sums never cross many-to-one links | A sum that would repeat a linked value once per row is refused when the model loads. |
| Typing errors aren't the latest date | A date fifty years ahead is never treated as the most recent; the answer says it was set aside. |
Every query result carries a certificate with everything needed to reproduce the exact table, far tighter than a loose citation pointing at a folder of documents. Identical inputs produce identical hashes, so a figure from last month's answer can be verified against the same model and data today.
{ "schemaVersion": "lazy-warehouse.query-certificate.v1", "certificateId": "qc_5f0c9a41d2e8b7c6a3f91e04", "modelSha256": "9b1e…", "dataAsOf": "2026-11-20T09:14:03Z", "query": { "measures": ["invoice_amount_total"], "by": ["currency"], "…": "…" }, "querySha256": "c4a7…", "measures": [{ "name": "invoice_amount_total", "agg": "sum", "currency_field": "currency", "…": "…" }], "entities": [ { "name": "invoice", "definitionSha256": "1d0f…", "dataSha256": "77ab…", "rows": 41210, "relations": ["xero.invoices"] } ], "result": { "sha256": "e930…", "columns": ["currency", "invoice_amount_total"], "rows": 3, "complete": true }}(The schema name comes from the research engine this grew out of.) A trace goes one step further: for a single cell it returns the underlying records, recomputes the figure from them and reports whether it reconciles, with each record pointing at its source and (where the model says how) a link to open it in the source system. The agent stores every certificate it cites with its run, so a reviewer can inspect the exact tables behind an answer. Our earlier piece on why every AI answer needs a receipt sets out the principle; this is the mechanism.
A certificate also states freshness twice: dataAsOf, when the engine last read changed rows, and a separate check time, when it last looked for changes. An hour-old data timestamp beside a current check time tells you nothing changed, not that syncing stalled.
Access isn't a filter bolted onto the answer. It's an input to the read. Every request names the organisation, the person verified by the control plane, and the warehouse views, channel data sets, channels and database relations that person can read. For that read, the engine touches only the entities those sources provide, anything derived from them alone, and the links between them. An empty list reads nothing.
There are two layers. The organisation's engine reads the governed views as no person, holding the organisation's shared rows. A person's slice reads per-person views (their own mail, for example) as that person, sharing everything else with the organisation's engine instead of copying it. Slices are built in the background, persisted on disk for fast restarts, and closed and rebuilt whenever an erasure removes someone's rows.
Every read the engine answers is written to the organisation's access ledger before the caller receives a byte: who read, which run or public call, and a hash of the input and counts, never the values. If a read can't be recorded, it isn't returned. The same rule holds whether the caller is our own agent, a person in the CLI, a tenant API key or an outside model over MCP.
A query asking for something the model lacks (a measure, a field, a link or an entity) gets a typed refusal, not_covered, listing the missing pieces. The agent is instructed to tell the user plainly that the organisation's graph doesn't cover that part and name what's missing, rather than estimating it. The run records the hand-off so we can measure coverage directly and add the measures people actually ask for. Refusals are also counted on the engine's log by measure, with no reader or value, so the measures agents hit most are first in line for a time rule or currency split.
"Our graph doesn't hold contract end dates yet" is a useful sentence. A plausible number pulled from the wrong column wastes everyone's afternoon.
In November we reviewed the whole engine (about 25,000 lines of Rust) and measured before claiming any speed-up. Because we don't load-test on customers' data, the benchmarks run against a synthetic organisation built to production scale: 224 entities, 446 measures, a ledger of one million rows over 2,000 accounts, two guarded feed entities of 150,000 rows, and 220 small entities.
The biggest sink sat right in the query loop. Every filter, dimension and measure cloned its cell for every row, text comparisons folded both sides to lower case on every row, and checking for a blank cell rendered the whole cell, which for a long document column meant copying 100 KB just to learn it wasn't empty. We changed it to read fields in place by column index, fold filter targets once, compare ASCII text without copying, and resolve a measure's time columns once per query. That change sits on main alongside the measurement harness, so every later edit is benchmarked against the same fixture.
Two other measurements shaped the rest of the work. Searching the engine's word index takes 0.5 ms; scanning every cell takes 299 ms. A person's own tables weren't indexed, so personal searches paid that gap on every query; they're now indexed in the background within a memory budget. And explaining an empty answer used to rerun the query once per filter (close to a second on a million rows), whereas it now takes a single pass.
Speed matters less for its own sake than for what it makes possible. A refresh used to block reads on one large organisation for close to a minute. The engine now builds each refresh alongside the live state and swaps it in whole, so any read sees either the state before the refresh or the state after, never a mix. A test races reads against 400 generations of refreshes to keep it honest.
Two standing suites query the live graph through the CLI with no model involved. An answer suite grades outputs against worked-out truth per question. Invariants need no ground truth at all: across every measure in every catalogue they check properties any sound engine must uphold: groups adding up to the ungrouped total, a filter and its negation partitioning the whole, and the top five matching the first five of the full ordering. Because they're generated from each catalogue, any new measure gets covered without anyone writing a test. It's the same approach as our guide to evaluating AI systems at scale, applied to a layer that should never be probabilistic.
Most teams who talk to us about AI over finance or operations data want numbers they can repeat in a board meeting without flinching. The pattern above is where we'd start.
Building certified answers over your data
None of this demands a new warehouse. It sits on the governed views you already have, and the business model behind it is a short, reviewable file. For why agreed definitions beat piling on more retrieval, see approved meaning, not more context, and for how retrieval and agents divide the rest of the work, our guide to RAG and agentic retrieval.
Every figure the Company Twin returns comes out of this engine, with a certificate and source trace attached. See certified answers in the Twin →