The client wanted a conversational assistant that behaves like a senior data analyst: an executive asks in plain language and gets a useful answer, not a dashboard. The conversation was never the hard part. The hard part was making a fluent model safe in front of people who act on its numbers, and keeping it safe once it met databases nobody had prepared for it.

The application: three connected databases on the left, a question about December's orders answered in the middle with a forecast chart, and on the right a step-by-step account of how the answer was made
The assistant at work: connected databases on the left, the conversation in the middle, and on the right the account of how the answer was made. Every screen on this page is the real interface over an invented company. No customer data appears anywhere here.

Context

The audience is senior, and the system is headed for operational data that people run a business on. One invented figure in front of a board ends the engagement. The data must also stay in the country: the brief was a sovereign deployment, on a model the client hosts itself. So the design could not count on a frontier model being careful, and could not trust any model with arithmetic.

The constraint

Language models are fluent with numbers and unreliable at producing them. Catching a fabricated figure after the fact is a bet that the reviewer is never wrong. So the first rule is structural. The model plans, queries and explains. It never calculates. A database engine or plain, tested code produces every figure; the model says what the figures mean.

First answer: an engine with receipts

The first version enforced that rule in the strictest way available. The model could reach only a registry of typed capabilities: hand-built, parameterised queries, run under the database's own row-level security. A deterministic engine computed each figure and minted a receipt for it: a content-hashed, tamper-evident record of what was computed, over what, and when. The model wrote the sentence, and a mechanical check compared every numeral in it with the engine's figures before anyone saw it.

It worked, and it had a ceiling. Every new question needed a new hand-built capability, and every new database its own set. A product that answers only the questions its engineer anticipated is a dashboard with better manners.

Second answer: any database, and a ladder of trust

The second version keeps the rule and removes the ceiling. Connect a PostgreSQL, MySQL or SQL Server database with a read-only credential, and minutes later the assistant answers questions nobody modelled in advance. It stays safe because an answer is never one model's unchecked work, and never claims more certainty than it has.

  • The model states its intent, then drafts one query. The intent is in business words, apart from the SQL, so there is something independent to check the SQL against.
  • An auditor checks the query against the intent. A second model, by default from another vendor, accepts the draft or rejects it with a reason. A rejected draft is not run. After a second rejection the assistant asks, or says it cannot answer; it does not serve a figure the control turned down twice.
  • A gate admits the query on its parsed form. Each dialect has its own gate, built on a real SQL parser: exactly one read-only SELECT, only tables pinned when the database was connected, a row cap, and no value in the result that the data did not produce.
  • Code works out the facts. Totals, shares, the highest and lowest, the period still running, placeholder dates, a projection with its range: all computed beside the rows and handed to the model. An early version got every number right and still called the wrong month the lowest, so comparisons come from code too.
  • The answer names its read and wears its label. It must cite the read behind its figures, and that read's rows are what the page charts. Everything on this path is labelled exploration: a best effort over a source nobody has certified.

Exploration is the first rung of a ladder. The second is certification: any answer's query can be saved as a verified metric. The model drafts candidates, a person reads the full SQL and certifies it, and from then on the engine re-runs that exact frozen text and mints a receipt on every run. A verified metric is named with what it is fixed to, "orders placed in fiscal year 2026" and never just "orders placed", and a question that adds a filter drops back to exploration and says so. At answer time the model is no longer in the loop.

A question goes to the model, which states its intent and drafts one query; an auditor checks the query against the intent; a gate admits it on its parsed form; the database reads the rows and code works out the facts; the answer cites its read and is labelled as exploration. A person can certify a query once, after which every run carries a receipt.Questionplain language, Arabic or EnglishModelstates its intent, drafts one queryAuditora second model checks the queryGatea parser admits one read-only SELECTDatabase, then coderows are read; code works out the factsAnswercites its read, labelled as explorationCertify oncea person reads it; a receipt on every run
One model drafts, another audits, a parser admits, a database computes, code states the facts. A person turns a good answer into a guaranteed one.

What an answer looks like

The company in these screens is not real. Tall Order Farms is an invented vertical-farming business with three small databases, one on each engine the product reads. The interface is real, every query shown passed the product's own gates, and every chart, forecast and note came from its own code.

Asked what to expect in December, the model does not guess. Code projects the figure from the last three complete months, takes the range from how far the last twelve spread, and leaves the running month out. The chart draws the forecast only because the answer states the figure code projected.

The answer to 'How many orders should we expect in December?': about 437, most likely between 421 and 455, with a line chart in which the running month is dashed and the December forecast is a hollow point with its range
A forecast with its reasoning. The running month is dashed, the forecast is a hollow point with its range, and one line under the answer says what was counted.

The auditor earns its seat

Ask for "fiscal year 2026" and a plausible query filters the order date to calendar 2026. It runs, it returns a number, and the number is wrong: 4,642 orders where the right answer is 5,262. Here the auditor rejects that draft before it touches the database, and says why. The second draft passes.

The turn's trace: the agent's first query counts calendar year 2026, the auditor rejects it because the question asks for the fiscal year, nothing is read, and the agent's second query, filtered on the fiscal year column, is accepted
From the turn's own trace. The first draft counted the calendar year, the auditor turned it down, nothing was read, and the rewrite used the source's fiscal-year column.

Honest about what the data cannot say

A count over a condition silently ignores the rows where that column is empty. When a large share is empty, code counts those rows with its own fixed query, and the answer must say how many it could not check.

An answer saying 14 sensors are due for calibration before the end of 2026, followed by the sentence that 212 of the 380 sensors have no calibration date recorded, so the count could not check them
Fourteen sensors are due. The more useful sentence is the second one.

An unusual figure is explained by what the data shows, never by a guessed cause. A spike gets its day-by-day breakdown from code. Asked why, the assistant reports which farm, which crop, and that no reason was recorded. It does not offer a campaign, a season or a data import, because the data shows none.

Asked 'Why was October so high?', the assistant answers that the data shows where the jump comes from, not why: all 31 write-offs logged on 14 October were at one farm, for one crop, and none has a reason recorded
"Why was October so high?" The data shows where. It does not show why, and the answer says so.

Charts come from code too

The model never chooses a chart. The server reads the result's shape: which column is a period, which numbers genuinely add up to a whole, whether the last period is still running. Only then does the page offer a line, columns, a donut or a stack. An average is never stacked, and a top five is never drawn as a share of everything. "Why this answer?" lists what the cited read touched.

Orders per month by channel as stacked columns, with the running month faded, and the 'Why this answer?' panel open, listing the tables read, the columns used and the condition applied
Stacked columns appear because the query is a plain count over time and one category. The running month is faded. Below the chart: what the answer read, and when.

From an answer to a receipt

Verified metrics are where the first version's guarantee returns, now for any database. The drafts are the model's, the decision is a person's, and the number is the engine's.

A verified metric, kilograms harvested in fiscal year 2026 by farm, answered with its receipt id above the answer and a bar chart of the four farms
A certified metric, answered by the engine from frozen SQL. The line under its name is the receipt.
A drafted metric marked Unverified: its name, what it is fixed to, a preview labelled as receiptless and for inspection only, and a Verify button
A draft waiting for a person. It says what it is fixed to, shows a preview that is explicitly not a receipt, and computes nothing official until someone presses Verify.

Three engines, one way of asking

PostgreSQL, MySQL and SQL Server each get their own gate, reader and traps: the SQL Server gate refuses a two-part table name, because on that engine the connection is not a boundary. Connecting a database is a paste and a wait: a read-only credential, a scan that reports its progress table by table, and a first answer minutes later. Access comes from the client's MCP gateway, so their IT team owns one door.

The source gallery: three connected databases, one each on PostgreSQL, MySQL and SQL Server, each with its tables, columns and three starter questions, and a card to connect a new source
Three sources on three engines. The questions under each were drafted when the database was connected.

Arabic first, inside someone else's product

The same assistant embeds in a customer's own web application. It signs people in with that application's token, takes its colour, opens in Arabic and right to left, and scopes every read to the signed-in person's company. Inside a customer's page no SQL travels to the browser at all. Column names, chart labels and saved questions follow the reader's language; figures stay in Western digits, so a number reads the same in the sentence and in the chart.

The chat embedded in an invented company portal, in Arabic and right to left: a donut chart of the quarter's harvest by crop, with the total in the middle and the crops named in Arabic
The chat inside an invented portal: Arabic, right to left, in the portal's own green. The donut is offered because the query is a plain total over one category.

Running it

The system runs on the client's Kubernetes platform, on its 37th release since late October. In November the self-hosted model's server changed its behaviour: every request that enforced the final answer's JSON schema ran to the token limit, so each turn took close to five minutes and failed. I reproduced it from inside the running pod, found that the same format given in words came back valid in five seconds, and shipped that as a per-model setting the same day. Then came the thing that should have caught it: a health check that runs one real turn through the live model every fifteen minutes and raises an alert on two misses.

Decisions worth reading

One hundred and thirty architecture decisions are recorded in the repository. Beyond the ones above, these carry the most weight:

  • A wrong fact is worse than none. A note written by code speaks only when the rows prove it. Before the standout-day note shipped, it ran over 32 date columns in the test databases: 29 notes, each recomputed by a separately written query, all correct, and every query shape that should stay silent did.
  • Somebody must be able to win an honest disagreement. The auditor sees one turn; the analyst sees the conversation. So the analyst may formally disagree, and then the read runs with the objection attached: shown, not buried. An auditor outage fails open, visibly and only once.
  • Two tiers of answer, never blurred. A verified answer wears its receipt, an exploratory one says it has none, and a mixed answer never claims to be verified.
  • Receipts hold the figure and its hashes, never the underlying rows. A number can be re-checked later without the evidence store becoming a second copy of the data.
  • The model is configuration. Any compatible endpoint can take either seat, a model whose schema enforcement fails gets the format in words, and the live one is checked with a real answer, not a ping.

Proving it works

The integration gate is CI on real engines. The last full run passed 8,085 tests against PostgreSQL 16, MySQL 8.4 and SQL Server 2022, including a parity suite that reads the same data through all three readers. Golden conversations pin whole turns. Changes to how facts are computed get an independent cold review and a fuzz; one such release was fuzzed over 200,000 generated reads.

For the first dataset I also built Data Invoker, a synthetic-data engine in which an invented persona causes every row, so the tool knows the truth. It ships an answer key with planted patterns and deliberate decoys, and a scoring contract that rewards a correct description over a wrong cause. "The analyst found the real signal" became a score.

How it was built

One person, held to team discipline. Every feature starts as a design note with testable acceptance criteria and lands through a pull request: 397 merged so far. A second model reviews code changes cold, from the diff alone; I own direction and the merge; tests own correctness. The repository holds about 104,000 lines of Python under more test code than product code. The interface's look began as a design prototype from a teammate on the client's side; wiring it to a real system, and everything behind it, is mine.

Result

A working analyst over three database engines, in two languages, embedded in a customer's product and running on the client's own platform: on test data today, and built for the day the data is real. It answers questions nobody modelled in advance, and tells the reader which answers are proven, which are a best effort, and what the data cannot say. Figures are from the repository on 18 November 2026.

What it demonstrates

How to make a language-model product safe for an audience that will check. Keep the model where it is good, planning and explaining, and out of where it is not, arithmetic and certainty. Put a second pair of eyes and a parser between the model and the database. Let code state the facts. And give people a way to turn a good answer into a guaranteed one.

All case studies

More case studies