That rule is the backbone of a multi-client monthly reporting platform built for an agency: five data connectors, a metric catalogue, deterministic QA gates, a model that drafts narrative, and a validator that refuses any sentence whose numbers do not match the fact table. This post is the detailed version of one line in the company AI workspace rollout: the platform’s output is prose about facts, never facts produced by prose.
The interesting part is not the rule. It is everything required to enforce it: a schema the model cannot escape, a validator that reads the sentence rather than trusting the schema, a repair loop with a hard bound, and a replay tool that reproduces the facts without re-querying a provider.
The rule: numbers from code, prose from the model
The rule is a division of labour. Every figure in a client report is computed by deterministic code from stored source data. The model receives those figures, the comparison windows, the findings and the approved context, and it writes sentences about them. It never receives a blank page and an instruction to calculate.
The reason is not that models are bad at arithmetic. A model’s output cannot be reproduced, diffed or unit-tested the way a function can. If a report says conversions rose 12%, that number should trace to a stored fact and a formula, not to a likely continuation.
The platform enforces the division at the type level. The model’s response schema has no free-form numeric field: a key metric is an object with a metric_id and a sentence, so the number in the prose has to match a metric the code already computed. A number that is not in the payload has no legitimate place to go.
Status matters here. The platform was deployed in September 2026; as of its status note, one client was onboarded and no report had been generated in production, so the pipeline was proven by fixtures and tests rather than live reports.
That still leaves the sentence. A model can write “conversions reached 123” when the fact is 122, and the schema will happily validate a string. The schema is necessary, not sufficient.
Deterministic metrics: the dictionary and the windows
The metric dictionary is the contract between the connectors and everything downstream. A connector may emit only catalogued metrics, each with a canonical id, a unit, a set of grains and a client-facing definition.
Two conventions do a lot of work. Values are stored unrounded and rounded only for presentation, so a 3.1% that is really 3.14% does not become a different number in a different view. And comparisons are computed with SQL window functions over the stored fact table, not by re-querying the provider, so month-over-month and year-over-year cannot drift from the number they are compared against.
Time gets the same treatment. Each client has one authoritative IANA timezone, and month boundaries are resolved as half-open [start, end) intervals in that timezone and stamped on the run. A re-run reuses the stamped boundaries, so rerunning a report in a different month does not silently change what “last month” meant. A provider timezone mismatch becomes a finding, not a quiet normalisation.
Before any model sees the data, four deterministic gates run: source completion, reconciliation, comparison validity and materiality. A failed gate blocks the PDF, publication and email. Those gates catch errors no amount of prompt engineering would fix, because they are not language problems.
The JSON schema that constrains the model
The narrative contract is a strict JSON Schema, requested at generation time rather than parsed out of prose afterwards. The shape is deliberately narrow:
| Field | Contains | Why |
|---|---|---|
overview |
Prose summary of the period | The only free-form paragraph |
key_metrics[] |
metric_id plus a sentence |
Ties every claim to a computed fact |
challenges_and_opportunities[] |
evidence_ids plus a certainty label |
Forces a citation for each claim |
next_steps[] |
An owner plus basis_ids |
Separates a recommendation from an observation |
caveats[] |
Known limits of the data | Makes degradation explicit |
review_required |
A boolean | Lets the model flag its own uncertainty |
Two choices stand out. The model does not return numbers as numbers; it returns a sentence that refers to a metric id. And it does not return claims without evidence ids. Both make the validator’s job possible, because a claim it cannot trace is visibly malformed rather than plausible.
Generation is one call per section, not one per report, so a single bad section can be regenerated without redrafting the whole thing. Each call asks for the schema explicitly and requires the provider to honour the requested parameters, which rules out a silent fallback to a looser mode.
The fact validator: five rules
The validator is gate five, and it runs before anything reaches the review queue. It reads the generated text, not the schema, because the schema cannot check whether a sentence is true.
- Every numeric string must match a metric in the payload, within that metric’s display tolerance. This is the check that catches a drift from 122 to 123.
- Every causal statement must cite an approved context item, or be rewritten as observational language: “coincided with” rather than “drove”. A model that cannot explain a cause does not get to imply one.
- Every next step must trace to approved context or a playbook, or be labelled a recommendation. Advice with no basis is allowed only if it is marked as advice.
- No claim of universal direction when any material segment contradicts it. “Traffic is up across all channels” is false if one material channel is flat or down, even when the total is up.
- No unsupported superlatives and no invented operational facts. The model does not know what the team did last week unless it was given the note.
The verdict is persisted with the draft: pass, soft-warn, or hard-fail with the offending spans. A soft warning is visible in review; a hard failure blocks the draft from reaching a human as if it were finished.
The fifth rule is the one that ages best. Models are fluent at adding plausible operational context (“after the site speed work shipped”), and every such sentence is a liability in a client document. Removing the capability is cheaper than correcting the output.
The repair loop, with a hard bound
A hard-failed section is fed back to the model with the validator’s findings attached, and retried up to three times. The bound is the important part. An unbounded repair loop turns a bad generation into an unbounded bill and a hung run.
Three attempts is enough for the common failures, which are mechanical: a number that drifted, a causal verb that needs replacing, a claim that needs an evidence id. It is not enough for a payload that is genuinely contradictory, and that is the correct outcome: the run fails and a human looks at the data.
Failing loudly is a feature here. A report that quietly ships with a validator warning treated as success is worse than no report, because the client reads it as fact.
Versioned prompts and the record of every draft
Prompts are versioned files, not strings edited in a database. The narrative row stores the prompt version alongside the model, an input hash, token counts, cost and the validator verdict. When a draft looks wrong three months later, the question “what instructions produced this” has an answer.
The review queue is the human gate: draft, edited, approved or rejected, with the metric payload and the validator’s findings side by side. Every edit writes a before-and-after row, the most valuable artefact the system produces, because it records where the model’s judgement diverged from a person’s.
Publication is immutable. A correction is a restatement with a reason and a change log, never an in-place edit. That matters for the same reason the numbers are deterministic: a client report is a record, and a record that changes silently is not a record.
Replay: snapshots in, facts out
Normalisation is a pure function of the raw provider snapshots, so it can be replayed without touching a provider. The replay tool reads a run’s stored snapshots and prints the facts it would produce, in under a second rather than a rebuild.
One real replay read 40 snapshots across five sources and produced 5,937 facts across 566 entities. It also printed a warning that a single unbatched insert would bind 77,181 parameters, over PostgreSQL’s 65,535 limit, which is exactly the class of bug that only appears at real data volume. The protocol carries the parameter count as a 16-bit integer, so the ceiling is structural, not a configuration choice (PostgreSQL protocol).
The replay tool exists because the alternative is guessing. It catches a connector that reports available and contributes nothing, facts landing on the wrong entity, a value the normaliser refuses, and a fact count large enough to overflow one insert. None of those produce an exception in production; they produce a plausible report with a hole in it.
Model-computed metrics vs model-written prose
| Approach | Reproducible | Testable | Failure mode | Review burden | When it fits |
|---|---|---|---|---|---|
| Model computes the metrics | No | No | A wrong number with confident prose | Re-check every figure | Never for client-facing numbers |
| Model writes prose with no validator | Yes, if facts are supplied | Only the schema | Right facts, wrong sentence | Read every sentence against the data | Internal drafts |
| Model writes prose, validator gates it | Yes | Yes, at the sentence level | Blocked draft or a failed run | Review flagged spans only | Client reporting, regulated summaries |
Which should you choose? If the output goes to a client, a regulator or a contract, compute the numbers in code and validate the prose against them. If the output is an internal first draft that a person will rewrite anyway, the validator is optional. The middle option, fluent prose over correct facts with no check, is the one that produces confident errors at scale.
What broke and what we changed
The draft said 123 where the fact table said 122. The schema validated, the prose read well, and the number was wrong. That single drift is why the validator checks numeric strings against the payload instead of trusting the model’s arithmetic.
“Traffic is up across all channels.” In the July audit, three material channels were flat or down while the total was up. The sentence was directionally true at the aggregate and false in the detail a client would check first. The validator now rejects a universal claim when any material segment contradicts it.
A 3,594.4% average-duration change from 14 sessions. Mathematically valid, decision-useless, and exactly the kind of finding a fluent model will lead with. A small-base rule now suppresses or qualifies changes computed on a handful of sessions.
Related
- Rolling out an AI workspace to a whole company — the pillar post and the platform this pipeline runs on.
- Building an OpenAI-compatible gateway in front of tools that are not APIs — where model calls enter the platform.
- LLM failover that actually fails over — what a failed generation should do next.
- One memory layer shared by several coding agents — provenance for a different kind of generated text.
- Model gateways and bridges — the wider body of work.
Frequently asked questions
Should an LLM ever calculate metrics?
No, not for anything a client will read. Compute the figure in code, store it unrounded, and give the model the computed value. Arithmetic in a model is unreproducible, untestable and impossible to audit after the fact, which is the opposite of what a report needs.
How do you stop a model inventing numbers?
Two mechanisms. The response schema has no free numeric field, so a claim must attach to a metric id, and the validator checks every numeric string in the sentence against the payload within a display tolerance. A model that wants to invent a number has to do it in prose that the validator will reject.
How many times should a failed draft be repaired?
A small fixed number, three in this system. The common failures are mechanical and clear on the first retry: a drifted number, a causal verb, a missing evidence id. If three attempts do not fix it, the payload or the instruction is wrong, and a human should look rather than paying for more samples.
Why version prompts instead of editing them?
Because a stored draft is only explainable if you know the instructions that produced it. A prompt version on every narrative row turns "why did the model say this" into a lookup. Editing a prompt in place destroys the history of every draft it produced.
What is a replay CLI for?
It reproduces a run's facts from the raw snapshots it captured, without calling a provider or rebuilding the stack. It is how you check a normalisation change against real payloads, and how you catch a connector that reports success while contributing nothing.
