We built an AI feature for an EU platform that manages regulated product data. A user uploads supplier documents: PDFs, spreadsheets, certificates. The model reads them and fills a product checklist. A person reviews the result, and then it is published.
In this kind of data, an invented value is worse than an empty field. An empty field gets attention. An invented value looks correct, passes review and goes live. So “no hallucinations” was a hard requirement, not a nice-to-have.
Values that look right
The eval found three kinds of fabrication:
- Placeholders. The model wrote values such as
<UNKNOWN>into fields that needed real data. - Computed values. A document stated two weights, 390 g and 412 g. The model calculated 94.66% and reported it as a stated fact. No document said that.
- Guesses from context. The model took a product name from the filename, not from the document.
A fourth problem was worse. One document described a different product. Its values spread into the checklist, and about half of that checklist was wrong.
More prompt rules did not hold
The first fix was the usual one: add rules to the prompt. “Do not calculate values.” “Do not use the filename.” The anti-fabrication text grew to about 80 words.
Each rule fixed the case that we had just seen. None of them stopped the next one. A prompt that grows with every bug also costs tokens on every call and spreads the model’s attention across more instructions. We call this the ever-growing system prompt, and we now treat it as a warning sign.
The prompt says what you want. Code decides what you accept.
Every value must quote its source
We moved the rule from the prompt into code. The model must return every value with evidence: the shortest quote, of 120 characters or fewer, copied word for word from the document. Code then checks two things. First, every part of the quote must exist in the document text. Second, the value must appear in the quote or in the same part of the document. Fields with units are different: they hold a converted number, so they must be a plain number.
// Evidence must be quotable from the source (ellipsis-joined fragments allowed).
// Empty evidence fails closed.
function isEvidenceGrounded(evidence: string, normalisedSource: string): boolean {
const fragments = evidence
.split(/\s*(?:\.\.\.|…)\s*/)
.map(normaliseForGrounding)
.filter((f) => f.length >= MIN_EVIDENCE_FRAGMENT_LEN);
if (fragments.length === 0) return false;
return fragments.every((f) => normalisedSource.includes(f));
}
function isValueGrounded(
value: string,
evidence: string,
normalisedSource: string,
isUnitField: boolean,
): boolean {
if (isUnitField) return PLAIN_NUMBER.test(value.trim());
const v = normaliseForGrounding(value);
if (v.length === 0) return false;
return normaliseForGrounding(evidence).includes(v) || normalisedSource.includes(v);
} The comparison ignores case and extra spaces, and quote fragments shorter than 4 characters do not count. A quote such as “no” or “12” proves nothing. If a check fails, the value is dropped. This blocked all three kinds of fabrication: a placeholder, a calculated percentage or a filename guess cannot be quoted from the document.
Then we cut the anti-fabrication prompt text from about 80 words to one clause. The code does the work now.
The same idea handles the cases that a quote check cannot cover:
- Confidence caps for review. A summary of a long text cannot be quoted word for word. It is kept only if its quotes check out, and its confidence is capped at 69%, so a person always reviews it. A value found directly after its own field label, as in “Material: cotton”, is raised to 90%.
- Product matching. Each part of a document reports which product it describes. Values from a document about a different product are capped at 39% and flagged for review.
- Structured output. The model must answer through a tool call with a fixed schema, so free text never reaches the checklist.
Make fabrication a hard gate in the eval
In the first eval, one invented field cost a case only 1 point out of many fields. A model could invent a value and still get a high score. We changed the rule: one fabricated field fails the whole case. The score now matches the real cost of the error.
The eval also found errors in our own expected answers. One expected product name came from a filename, which is the same mistake that we had blamed on the model. We marked that field as “missing”. Field accuracy on that case went from 79% to 95%.
The result
With the grounding check in place, a smaller and cheaper model became good enough.
| Before | After | |
|---|---|---|
| Model and pipeline | Claude Sonnet 4.6, prompt rules | Claude Haiku 5.5, grounding check |
| Cases passed | 66.7% | 100% |
| Field accuracy | 0.923 | 0.976 |
| Fabricated fields | 1 | 0 |
| Failed files | 3 | 0 |
| Cost per eval run | $0.64 | $0.037 |
The change in the pipeline did most of the work. On the same Haiku model, the pass rate went from 58% to 75%, then to 92% and then to 100% as the pipeline improved. The model only became the cheap choice after the system around it was correct. Then it cost about 17 times less per run.
Ask the model for a word-for-word source quote with every value. Check the quote in code, and reject the value if the check fails. Cap confidence where a person must review. In your eval, let one invented value fail the whole case.
Integration is mostly the code around the model
The model call was a small part of this feature. Most of the work was in the code around it: grounding checks, confidence rules, product matching and an eval that scores errors by their real cost. That code is what lets a regulated business trust the output.
To check whether your own eval tells the truth, read your LLM eval is overfitting. If you want to put AI into a product where errors cost money, see how we integrate AI.