In brief
A hallucination is a language model response that sounds credible but is false or does not follow from the data: an invented item number, an amount that is not on the invoice, a regulation that does not exist. It cannot be eliminated completely, because the model generates probable text and does not check facts. It can be limited in the process: give the model source data, check its output with rules in code and against data in your systems, let it answer “I don't know,” and leave irreversible steps to a person.
Where hallucinations come from
A language model predicts the next fragments of text based on patterns from training and the content it received in the prompt. It has no built-in mechanism that tells “I know” from “sounds likely.” If the prompt lacks information, the model often fills the gap with whatever fits the pattern.
In its generative AI risk profile, which supplements the AI Risk Management Framework, NIST calls this phenomenon confabulation. In its Top 10 for LLM Applications, OWASP describes it as misinformation and points to the other side of the problem: people's excessive trust in the output.
In company processes, hallucinations most often appear in three places:
- numbers and identifiers: an order number, tax ID, item number, amount,
- references: a contract clause number, a procedure name, a regulation,
- filling in gaps: a field that is not in the document, for example a payment term on an invoice that has none.
An example from a purchasing department: a model reads an invoice on which the customer's order number is illegible. Instead of reporting the gap, it enters a number that looks correct and fits the format the company uses. If nobody checks, the invoice is matched to the wrong order, and the error surfaces only when balances are reconciled with the supplier.
Rule one: source data instead of the model's memory
The most effective way to limit hallucinations is to give the model the data it is supposed to work on and tell it to stick to that data only. A model that has an invoice and an order in front of it compares documents. A model that has only a question answers from memory.
In practice this means:
- The document in the prompt. The AI Worker receives the content of the invoice, the order, and the goods receipt, not a description of them.
- Search over company documents. For questions about procedures and contracts, the model receives document fragments with a link to the source, as we describe in the article RAG: how AI uses company documents.
- Data from the system instead of from the document. Price, stock level, and credit limit come from the ERP, not from the model's memory or from a PDF that is a month old.
- A citation requirement. Every claim in the output points to the place in the source document it comes from.
It is also important to separate instructions from data. The prompt tells the model what to do, and the document is clearly marked as material to read, not as a source of commands. This reduces the risk that text in an e-mail from a supplier is treated as an instruction.
Rule two: check the output in code, not in the model
The model's output is checked with rules in ordinary code, not with another prompt saying “check whether you made a mistake.” Rules are deterministic and do not hallucinate.
| What to check | How |
|---|---|
| Counterparty tax ID (NIP) | check digit and comparison with the record in the ERP |
| Bank account number | IBAN check digits and comparison with the account in the vendor record |
| Invoice amounts | the sum of line items equals the net amount, net plus VAT equals gross |
| Item number | the item exists in the item master and is active |
| Order number | the order exists in the ERP and belongs to this supplier |
| Quote from a document | the quoted passage actually appears in the document |
The model reads data from a document and returns it in a defined format, for example as JSON fields. Code checks each field. If a rule fails, the case goes to a person with a description of which rule failed. This is how the rules sheet of the Purchase Invoice Checker works in the DYNAMINDS Labs process: it checks the tax ID and amounts, compares them with the order, and only then describes the invoice.
Rule three: permission to say “I don't know”
A model that is not allowed to answer “I don't know” guesses. That is why the prompt for an AI Worker must allow for a “no data” answer, and the process must have a path for it.
- An invoice with no payment term: the field stays empty, and the AI Worker reports the gap instead of entering a typical 30 days.
- An order with an unknown item number: the AI Worker proposes the few closest items from the item master but does not choose any of them.
- A question about a procedure that is not in the documents: the answer is “I did not find this in the documents” instead of a summary of general knowledge.
An exception reported by the AI Worker costs a few minutes of a person's time. An error passed through as correct costs a correction, a complaint, or a dispute. We show how to calculate these two costs in the article How to calculate whether an AI Worker pays off.
Rule four: testing and oversight
The hallucination rate in a given process is measured with tests, not with the model vendor's claims. A test set is a few dozen to a few hundred real cases from a data sample, with the correct result set by people. After every change of model, prompt, or rules, the set is run again, like regression tests in software.
It is especially worth counting two kinds of errors separately:
- false passes: a case marked as correct although it contains an error,
- false exceptions: a case sent to a person although it was correct.
The first kind is more dangerous, and it decides which steps can stay without approval. The second kind costs team time and discourages people, but does no harm.
Tests before deployment are not enough, because production data changes: a new supplier arrives with a different invoice layout, the price list changes, a customer starts using its own product codes. That is why, after launch, a sample of cases approved without changes is reviewed every month and compared with the source documents. Irreversible steps, such as posting or a transfer, wait for a person regardless of test results, as we describe in the article Human in the loop: when AI decides and when it only proposes.
Questions and answers
Have newer models stopped hallucinating?
No. Newer models usually make fewer mistakes on typical tasks, but the text generation mechanism has not changed, so hallucinations still happen. That is why safeguards in the process, meaning source data, validation in code, and approval by a person, are needed with every model.
Does a low model temperature solve the hallucination problem?
No. A lower temperature makes answers more repeatable, but the model can repeatedly give the same wrong answer. Temperature is a setting for the style of generation, not a fact-checking mechanism. Limiting hallucinations starts with source data and control rules.
Can a second model check the first one?
It can help, for example by flagging answers for another look, but it does not replace rules in code or comparison with data in your systems. Two models can make the same mistake, especially when both lack source data. Treat a check by a model as an additional signal, not as a control.
How do you detect hallucinations after deployment?
Through people's corrections and control rules. Every change a person makes to a draft before approval goes into a log and a monthly report. A rise in corrections of one kind, for example in item numbers, is a signal that you need to change the input data, the prompt, or a rule.