
AI hallucinations are model outputs that sound plausible but do not follow from the source, or are simply untrue. No single setting or sentence in the prompt switches them off. You can, however, design the application so that an invented value never reaches the accounting system, a contract or a reply to a customer: the model gets a narrow task, answers in a fixed structure and points to its source, and every result passes through control rules, a second independent reading and, where there is doubt, a person.
For anyone commissioning software, AI hallucinations are first a question of responsibility: who checks what the model proposed, and where. Below are the design patterns we use when we build web and mobile applications with AI modules, with accounting documents as an example of the result they lead to. The article is for company owners, CFOs and heads of IT and requires no programming knowledge.
In a few places we refer to KSeF, Poland’s National e-Invoicing System (Krajowy System e-Faktur), as one of the data sources used for checks. Legal status as of November 2026. This article is for information only and is not legal or tax advice.
What are AI hallucinations and where do they come from?
A hallucination is a result the model generated with no basis in the input data or in its training material. A large language model (LLM) does not look facts up in a database. It predicts the next pieces of text that best fit what it already sees, and “best fit” here means “most probable”, not “verified”. If the document lacks information, the scan is illegible or the question goes beyond the material supplied, the model can still produce a fluent answer in the correct format, because that is what it was trained to do.
In business applications the problem takes several forms:
- An invented value. The document has no purchase order number, but the answer field is filled with a string that looks like one.
- A “corrected” value. The model sees an illegible digit in a tax identification number (in Poland, the NIP) or bank account number and inserts one that makes the number look credible.
- A value from the wrong place. The date of sale lands in the issue date field, and a line item amount in the document total.
- An invented source. An assistant answers a question about a procedure and cites a clause that the company rules do not contain.
- A distorted summary. A reservation or condition disappears from a contract summary, which reverses the meaning of the clause.
- An invented action. A model that can call functions in other systems reports a step it did not perform, or calls a function with a parameter nobody gave it.
OWASP includes this risk in its Top 10 for LLM Applications (2025) as LLM09 Misinformation, alongside threats such as prompt injection. For a buyer this is good news: it is a known, documented class of risk with proven ways of handling it, not a mysterious defect of one tool.
Does AI make mistakes differently from ordinary software?
Yes, and that difference determines how the checks have to be designed. Conventional software fails repeatably: the same error appears with the same data, usually ends in an error message or an empty field, and can be reproduced in tests. A language model fails irregularly and convincingly. It returns a result in the correct format, phrased with confidence, and may return a different one when run again. Such an error is not visible at a glance, so control cannot depend on someone happening to notice it.
Optical character recognition (OCR) has a similar problem. It is a mature technology that handles clean, repeatable documents well, but it confuses similar characters on poor scans. An OCR error often gives itself away as an unnatural string of characters, whereas a model’s error looks like a valid value. We compare the two approaches in the article on why classic OCR gets invoices wrong and what an AI application changes.
Where are AI hallucinations dangerous in a business application?
They are most dangerous where the model’s output moves on without a person involved and has a financial, legal or reputational effect. The process, not the model, decides whether an error is acceptable. A draft email reply that a salesperson will read before sending anyway tolerates errors well. A bank account number passed on for a payment tolerates none.
| Process | What a hallucination can look like | Consequence for the company | Level of control required |
|---|---|---|---|
| Reading invoices and other accounting documents | A wrong digit in a tax number, account number or amount; an invented purchase order number | Posting to the wrong counterparty, a wrong payment, corrections | Every field checked by rules, doubtful fields go to a person |
| An assistant that answers from company documents | An answer the documents do not support, a non-existent clause of a procedure | An employee follows a rule nobody ever set | Answers only with a quotation and a reference; no source means no answer |
| Customer service | A promise of a discount, a deadline or return terms the company does not offer | Complaints, a dispute with the customer, loss of trust | A closed set of answers, handover to an employee |
| Contract review | An omitted reservation, a wrong notice period | A decision based on a faulty summary | A summary with quotations, assessment stays with the lawyer |
| Reports and summaries | A figure “calculated” by the model, not by the database | The management board receives untrue data | Code does the calculations, the model at most describes the result |
| Automatic actions in other systems | An operation called with a wrong parameter | Changed data, a message sent, an order placed | Narrow permissions, confirmation of irreversible operations |
The rule that follows is simple: match the level of control to the consequence of an error. Where a mistake costs a correction in a draft, the author’s review is enough. Where it costs a wrong payment or false information for a customer, control has to be built into the application and must not depend on anyone’s attentiveness. We cover customer service separately in the article on an AI chatbot in customer service.
The design principle: the model proposes, the application verifies
A reliable AI application separates two roles. The model does what it is good at: reading an unstructured document, understanding context and recognising that “Buyer” and “Purchaser” mean the same field. The application does what the model is unreliable at: calculating, comparing values with master data, enforcing the format and recording who approved a result and when. In this architecture the model’s answer is a proposal that becomes data in the system only after passing the checks.
A single piece of information usually takes this path:
- The application prepares the input: the document, the question and only the supporting data the task needs.
- The model returns an answer in a fixed structure, with a pointer to the place in the source each value comes from.
- The application checks the structure and the data types, and then whether the indicated fragment really exists in the document.
- Control rules verify the values: checksums, arithmetic, master data, duplicates and consistency with data from other systems.
- Where justified, a second, independent reading is performed and the results are compared.
- From these signals the application calculates a confidence level for each field and compares it with a threshold.
- Fields above the threshold move on. Fields below it go to a queue for a person, with a note on what raised the doubt.
- Every step is logged, so that anyone can reconstruct where a value came from and who approved it.
None of these layers is watertight on its own. An arithmetic rule will not detect an error in a counterparty’s name, and the master data will not detect a wrong date. Reliability comes from the layers having different weak points, so an error that slips through one is stopped at the next. For the same reason a project starts with a question about the process and the consequences of mistakes, and the choice of model comes later.
How can you limit hallucinations at the reading stage?
Narrowing the task does the most: the less the model has to know by itself, the less room it has to guess. The four techniques below concern how the application talks to the model, before it starts checking the result.
A closed context instead of general knowledge
The model answers only from the material supplied: a specific document, fragments of a knowledge base, a record from a system. The prompt states plainly that an answer from outside this material is not allowed. In assistants built on company documents this is done with retrieval-augmented generation (RAG): the application first retrieves the relevant fragments, and the model formulates the answer from them alone. We describe how to build one in the article on a company knowledge base with AI. The prompt alone is not enough, so further techniques are needed, but without it the other layers have far more work.
Structured output and schema validation
Instead of free text, the model returns data in a strictly defined structure, for example JSON that conforms to a schema. The schema lists the fields, their types (date, number, text), the permitted values of fixed-list fields, and which fields are required or optional. The application rejects every answer that does not fit the schema, and either repeats the request or routes the document to a person. Schema validation does not check whether the values are true. It does remove a whole class of problems: missing fields, a date in the amount field, a currency not on the list, a model comment pasted into the middle of the data.
Source grounding: where each value comes from
For each value the model states the place in the document it was read from: the page number and area, or a literal fragment of text. The application checks mechanically whether the fragment exists and contains the stated value. If it does not, the value is treated as unconfirmed. The same mechanism works in assistants: the answer consists of statements accompanied by quotations, and the application verifies that the quotations appear in the source documents. There is a purely practical benefit too: an operator who receives a field to check sees the highlighted scan fragment and does not have to search three pages for it.
The right to answer “I don’t know”
The answer schema must allow missing data as a fully valid result: an empty field marked “not found in the document”, or, in an assistant, the sentence “the available documents do not contain an answer to this question”. A model without this option will fill the field with something, because the format demands it. The application, in turn, must not treat an empty field as a failure. A missing purchase order number on an invoice is information the process should be able to work with, for example by routing the document to the person who knows what the purchase was for.
How to verify the result: control rules, a second reading and confidence thresholds
After the reading comes the part the model does not perform: verification. It relies on three mechanisms: rules calculated by code, a comparison of two independent readings, and thresholds that decide what may pass automatically.
Control rules calculated by code
Rules are deterministic checks that always give the same result for the same data. For accounting documents they include:
- checksums of the tax identification number (NIP) and the IBAN bank account number, which catch typical digit mistakes,
- arithmetic: net plus VAT equals gross, the line items add up to the total, the tax amount corresponds to the rate,
- counterparty master data: the tax number, name and bank account match the company’s records of suppliers and customers,
- duplicates: a document with this number from the same counterparty has not already been entered,
- dates: they are possible and consistent with one another,
- consistency with another source: the purchase order, the delivery document or the structured invoice data in KSeF, if the document has a counterpart there.
Everything that can be calculated is calculated by code. The model does not add up line items or convert currencies. If a figure is to appear in a report, it comes from a database query, and the model at most describes it. The list of rules is drawn up with the department that knows the documents, because the accounting team knows which relationships always hold and which have exceptions.
A second independent reading
The same document is read by a second method and the results are compared field by field. The key word is “independent”: the two methods should make mistakes in different ways. This can be a classic OCR engine paired with a model that analyses the page image, or two different models. Asking the same model again gives weaker protection, because it repeats some of its own mistakes. Agreement between the two readings raises the confidence of a field, and a discrepancy sends it to a person. The cost is additional computing time, so the second reading is sometimes applied only to critical fields, or only when the first check raised a doubt.
Confidence thresholds set for fields, not for documents
A model’s own statement that it is sure of its answer is not a reliable measure, because a model can be equally sure of a correct value and an invented one. Confidence is built from external signals: whether the field passed the rules, whether both readings agree, whether the value appears in the master data, whether the indicated source fragment contains it. The threshold is set separately for each kind of field, depending on the consequence of a mistake. An account number and an amount payable require all signals to agree. A line item description can pass under milder conditions. Thresholds are a business decision: they are agreed with the process owner and adjusted after the pilot.
Human-in-the-loop: when does the application hand the decision to an operator?
The application hands the decision to a person whenever a field has not reached its confidence threshold, a control rule has reported an inconsistency, or the operation is irreversible. Human-in-the-loop does not mean that someone reviews everything after the model, as automation would then be pointless. It means that the application can identify the places it cannot confirm by itself, and shows the operator only those.
A well-designed verification queue has several features:
- it shows the document with the field highlighted and the reason for the stop, for example “tax number checksum mismatch”, “readings disagree” or “counterparty not in master data”,
- it requires a decision on each field (approve, correct, reject) and does not encourage approving in batches,
- it records who changed what, and when,
- it passes the operators’ corrections to the test set used to check later versions of the application,
- it has assigned roles and deputies, so that the queue does not grow during holidays and at month-end closing.
There is one more reason to send only genuinely doubtful cases to the queue. A person who sees nothing but correct proposals for a long time starts approving them by reflex. The fewer items in the queue and the clearer the reason for each stop, the greater the chance that each one really gets checked.
| Role | What it is responsible for in an AI application |
|---|---|
| Process owner, e.g. the chief accountant or operations manager | Defines fields, rules and exceptions, sets thresholds, accepts the results of the pilot |
| Operator | Resolves fields from the queue, reports new document types and recurring problems |
| Administrator on the company’s side | Grants permissions, looks after master data and integrations with source systems |
| Company that builds the application | Maintains the test set and regression tests, changes the model and the rules, reports on quality |
How much does reliability cost? Techniques, what they do and what they cost
Every layer of control costs design work, computing time or people’s time, and the amounts depend on the project, so we give the type of cost rather than a price list. The table helps to decide which techniques a given process needs and which can safely be left out.
| Technique | What it protects against | Cost |
|---|---|---|
| Closed context and a narrow task | Answers “from the model’s memory”, from outside the material supplied | Design work on prompts and data preparation, low running cost |
| Structured output with schema validation | Missing fields, wrong types, values from outside the list, text instead of data | Small, mainly repeated requests after rejected answers |
| Source grounding and its mechanical verification | Values and quotations that are not in the document | Longer model answers and an additional comparison step |
| Control rules: checksums, arithmetic, master data, duplicates | Wrong digits, amounts and counterparties, a document entered twice | Analysis with the business department and upkeep of master data, negligible computing cost |
| Comparison with another system: purchase order, delivery, KSeF | Values that are formally correct but do not match the facts | Integrations with source systems |
| Second independent reading | Errors of a single method that no rule detects | Additional computing time per document or per field |
| Confidence thresholds for fields | Automatic acceptance of weakly confirmed values | Tuning the thresholds on pilot data |
| Human-in-the-loop | Everything the application cannot confirm by itself | Operators’ working time, building the queue interface |
| Declining instead of guessing | Gaps filled with invented values | Handling empty fields in later steps of the process |
| Test set and regression tests | A drop in quality after a change of model, prompt or rule | Preparing and maintaining a set with confirmed results |
| Monitoring in production | A slow decline in quality, new document types | A log, reports, periodic checks of a sample |
Not every process needs all the layers. An assistant that helps employees find a procedure needs, above all, a closed context, quotations and the right to decline. An application that passes data on for payment needs the full set. The cost of the safeguards is weighed against the cost of an error and the time the team now spends on manual checking. We describe that calculation in the article on how to calculate the return on an AI deployment.
An example from one of our deployments: accounting documents indexed with 100% accuracy
In one of our deployments, an AI application processes very large volumes of accounting documents and indexes them with 100% accuracy, where classic OCR still makes mistakes. We report this as the result of a specific, completed deployment, not as a promise made in advance for every project.
Such a result is achievable because the application does not trust a single reading. It combines AI reading with control rules: checksums of the tax number (NIP) and the IBAN, the arithmetic of net, VAT and gross amounts, the counterparty master data, duplicate detection, and comparison with the purchase order and with KSeF data. Every field that could not be confirmed goes to a person, so nothing unverified enters the accounting system. The accuracy is therefore a property of the whole application, that is, the model, the rules and the verification queue together, not of the model alone. In this setup the model can still propose a wrong value. The proposal does not become a record in the system, however, until it has passed the checks.
There is also an honest condition: the result depends on the documents and on the control rules. Accounting documents lend themselves to this kind of control exceptionally well, because many fields have checksums, arithmetic relationships and counterparts in other systems. In processes with fewer such anchor points, a larger share of the work falls to people. That is why in every project we measure accuracy on the client’s own documents during a pilot, before the system goes into production, and only on that basis do we set the thresholds and the scope of automation.
Illustrative example (a scenario that shows the mechanism, not a description of a specific client). A finance department receives a scan of an invoice with a stamp that partly covers the seller’s tax identification number. The model reads the number, but has to guess one of the digits from under the ink. The application calculates the checksum and finds a mismatch. The second reading gives a different digit in the same place, so the doubt is confirmed. The counterparty master data suggests a company with a matching name and bank account whose tax number differs from the reading by one character. The field goes to an operator with the scan fragment highlighted, the reason for the stop and the suggestion from the master data. The operator compares the number with the scan and approves the right one. The invoice’s remaining fields passed the checks and did not need the operator’s attention.
We describe the full architecture of such an application, from document intake to export to the ERP system and the archive, in the article on how automated accounting document processing works.
How do you check the reliability of AI before and after deployment?
You check the reliability of AI by measuring it on your own data: before deployment on a test set and in a pilot, and after deployment through continuous monitoring. A model provider’s statements and general benchmark results say little about how the application will cope with a particular company’s documents.
A test set built from the company’s documents
A test set is a collection of real documents whose correct values have been confirmed by hand. It should reflect the daily inflow, not only model cases: poor scans, multi-page documents, corrective invoices, foreign documents, suppliers with unusual layouts. Results are counted per field, not per document, and fall into three groups: fields accepted automatically and correct, fields routed to a person, and fields accepted automatically and wrong. The third group is the silent errors, and it decides whether the application can be trusted. The second group decides how much work is left for people.
Regression tests with every change
Every change to a prompt, a rule, a threshold or the model version is checked on the entire test set, and the results are compared with the previous ones. A change that improves the reading of one type of document can make another worse, and without such a comparison nobody will notice. This applies in particular to models available through an API, which providers update and retire on their own schedule. The model version should be stated explicitly in the configuration, and a version change should pass the same tests as a code change. It is most convenient to include these tests in the application’s automated build and deployment process (CI/CD), which we run as part of our DevOps services.
A pilot on current documents
In a pilot the application works on the current inflow of documents alongside the existing way of working, and the results of the two paths are compared. This is the time to tune the thresholds, add to the rules the exceptions nobody foresaw at the workshop, and check whether the verification queue is convenient for the operators. The decision to go into production is based on the figures from the pilot, not on a presentation.
Monitoring after go-live
After go-live several indicators are watched: the share of fields routed to a person, the number and kind of operators’ corrections, the waiting time in the queue, and the results of periodic random-sample checks of automatically accepted fields. A sudden rise in queued fields usually means a new document type or a change at a supplier, and is a signal to extend the rules and the test set. We write more about post-deployment duties in the article on application maintenance.
Common design mistakes and questions to ask your development company
The most common mistakes in AI projects
Most reliability problems stem from a handful of recurring design decisions:
- a request “do not make things up” in the prompt, treated as the only safeguard,
- trust in the confidence the model declares instead of in independent signals,
- a test on a handful of model documents, which shows what the model can do, not how the application behaves in daily work,
- the same model in the role of author and reviewer,
- sums, conversions and comparisons entrusted to the model instead of code,
- a process that cannot accept an empty field, which forces the model to fill it,
- a one-off measurement before deployment and no monitoring afterwards.
Overly broad permissions are a separate category. A model that can send messages or change data in other systems needs limits and confirmations, especially as the content of a document or email may try to change its behaviour. We discuss this in the article on AI application security.
Questions to ask the company that will build the application
- What happens to a field the application cannot confirm?
- Which control rules will be created for our documents, and who on our side will help to define them?
- Does every value have a pointer to its place in the source, and does the operator see it?
- On what test set will accuracy be measured, and will those be our documents?
- Are errors counted at field level, and are the ones that passed automatically reported separately?
- What happens when the model version changes?
- Where are the documents processed, and who has access to them?
- What will we see in the log when, a year from now, we need to explain where a particular value came from?
A company that designs for reliability will answer these questions specifically, without appealing to the model’s “intelligence”. An answer such as “the model is good enough that checks will not be needed” is a reason to ask more questions.
FAQ: frequently asked questions
Can AI hallucinations be eliminated completely?
Not in the model itself, because generating a probable answer is how it works. In the application, you can make sure that an invented value does not reach the target system: the model’s output passes through validation, control rules and a second reading, and a person resolves the unconfirmed fields. The aim of the design is therefore to stop mistakes before they have consequences, not to have a model free of them.
Does AI make mistakes when reading invoices and documents?
Yes. Every reading method makes mistakes, especially on poor scans and on documents with stamps, handwritten notes and unusual layouts. A model that reads the page image copes with many cases where classic OCR fails, but its errors look like correct values. For this reason reading is always combined with verification by rules and a queue for a person.
What is human-in-the-loop in an AI application?
Human-in-the-loop is a design in which the application passes to an operator only the fields or decisions it could not confirm by itself. The operator sees the document, the highlighted fragment and the reason for the stop, and the decision is recorded in the log. Automation then covers the certain cases, while responsibility for the doubtful ones stays with a person.
How do you check the reliability of AI before deploying it in a company?
Measure it on your own documents. Prepare a test set with manually confirmed values, then run a pilot on the current inflow in parallel with the existing process. The most important result is the number of fields accepted automatically and wrong, and the second is the share of fields routed to a person.
Can an AI application enter data into an accounting system without human involvement?
It can, for the fields that have passed all the checks and reached the agreed confidence threshold. The remaining fields go to an operator, and the scope of automatic acceptance is set after the pilot together with the person responsible for accounting. In one of our deployments such an application indexes accounting documents with 100% accuracy, but in every project we measure the result on the client’s own documents in a pilot, because it depends on the documents and the rules.
Do AI hallucinations also occur in a model running on your own server?
Yes, where the model runs does not change how it works. Your own server does give you control over document confidentiality and over the model version, which will not change without the company’s decision. The patterns in this article apply equally to both variants.
What does the cost of protecting an application against hallucinations depend on?
It depends on the number of fields and document types, the number of control rules, integrations with source systems, the scope of the second reading and the design of the verification queue. Preparing the test set matters as well. The quote is individual and free of charge, and we prepare it after a conversation about the process and the documents.
How we can help: a free quote for an AI application
We design and build custom web and mobile applications, including ones in which AI reads documents, classifies them, searches company knowledge or automates repetitive steps. We treat the patterns from this article as part of the design from day one: we agree the scope of control, the thresholds and the verification queue with the process owner, and we measure accuracy in a pilot on your documents. We choose the technology to fit the project. Models can run on our GPU servers in Poland, so that documents do not leave the country, or through an API if you prefer. We can also maintain and monitor the application, and our own penetration testers check its security as part of penetration testing.
The quote is free and without obligation. We start with a conversation about the process, the documents and the consequences of mistakes, and then present an estimate of scope, schedule and budget. See how we work on the web and mobile app development page, or write to us and describe the process you want to improve.
