How to detect hallucinations in a local model on your documents
Short answer: a local model hallucinates for the same reason a cloud model does: it predicts plausible text, it does not know the truth. What changes is that you can inspect the pipeline: the retrieved chunks, the prompt, the model version and the quantisation. Detecting hallucinations is not a matter of asking the model "are you sure?". It is a matter of checking every claim against the source, with a small test set and a citation rule.
This guide gives you a method you can run on your own documents: build the test set, test grounding, count hits and abstentions, and fix the pipeline. Checked 5 November 2026; the method does not depend on a specific model, and no performance figures are promised here.
Why a local model also invents
A language model generates the next token from patterns. It has no database of verified facts and no internal flag that says "this is false". A local model can be more prone to invention when it is small, when the retrieved context does not contain the answer, when the prompt pressures it to answer, or when the context is long and the relevant sentence is buried.
Three common causes in a local RAG:
- Retrieval miss. The right chunk never reached the prompt, so the model fills the gap with general knowledge.
- Context ignored. The chunk is there, but the context window is too small or the model prefers its prior. Ollama's default context on GPUs under 24 GiB is 4096 tokens; RAG fragments can exceed it.
- Prompt pressure. "Answer the question" without an escape route pushes the model to produce something even when the documents do not contain it.
Quantisation and model size matter, but they are not the whole story. A Q4 model can answer a well-grounded question correctly, and a larger model can still invent a citation. Test the pipeline, not only the model.
Prepare a test set with your documents
You need 20-30 questions with known answers, drawn from the documents you actually use. Write the expected answer and the exact source (file and page) before you run the model. This is your ground truth; without it, you are judging fluency.
Questions with an exact answer
Ten to fifteen questions whose answer is a sentence, a date, a name or a number in one document. Include easy ones and at least one that requires combining two paragraphs. For each, write the expected answer and the page. If you cannot find the answer yourself, the question is not a good test.
Trick questions
Five questions with a false premise: a date that is wrong by one year, an author who did not write the document, a figure with the wrong unit. The correct behaviour is to reject the premise or correct it, not to answer as if it were true. This is where a model that only agrees with the user fails.
Questions without an answer
Five questions whose answer is not in the corpus but sounds as if it could be. The correct behaviour is "the documents do not contain that". Count how often the model invents an answer. This is the most useful test for a client-facing assistant.
Grounding tests
Grounding means the answer is supported by the retrieved source, not by the model's memory. Test it in two steps: first the claim, then the citation.
Is the answer in the source?
Break the answer into claims. A claim is a sentence that can be true or false: "the contract ends on 31 December 2027", "the study used 120 participants". For each claim, find the sentence in the source that supports it and label it:
- Supported: the source says it, directly or by a clear inference.
- Not found: the source does not say it; the model added it.
- Contradicted: the source says the opposite or a different figure.
This claim table is the core of the method. It turns a vague "the answer looks right" into a count you can track.
Does the citation exist and say that?
Open the cited file and page. Check three things: the file exists, the page exists, and the quoted sentence (or its paraphrase) is there. A citation that points to the right file but the wrong page is a partial failure; a citation to a page that does not exist is a fabrication. If the answer cites a paper, book or URL that is not in your corpus, verify it independently before trusting it.
Practical metrics
You do not need a benchmark suite. Four counts from your test set are enough to see whether the pipeline is usable.
Hits, errors and abstention
For the answerable questions, count correct, partially correct and wrong. For the unanswerable ones, count correct abstentions and false answers. Report them as fractions of your own set: "12 of 15 correct", not a percentage that sounds like a benchmark.
Abstention is a feature, not a failure. A model that says "not in the documents" on five unanswerable questions is safer than one that answers all five confidently. The dangerous number is the false-answer rate on unanswerable questions.
Correct citation rate
For every answer that includes citations, count how many citations point to the right file and page and actually support the claim. Divide by the number of citations given. Also count the claims that should have a citation but do not. A high citation rate with a low support rate means the model cites beautifully and invents the content.
Signs of hallucination
Dates, figures and names
These are the most common inventions because they look precise. A date that shifts by a year, a figure with a different unit, a name spelled two ways, a percentage without a source, a law article that does not exist. Check every number against the original; do not trust a number that appears only in the summary.
Overconfident answers
"According to the document" followed by no page, "the study clearly shows" without a quote, or an answer that never says "I don't know". Confidence is a style, not evidence. A model can be polite, fluent and completely wrong. The same goes for a self-reported "confidence: high"; it is generated text, not a calibrated probability.
How to improve the model
Prompt and output format
Give the model an escape route and require evidence. A useful instruction: answer only from the context; quote the sentence that supports each claim; cite file and page; if the context is insufficient, say "not in the documents"; do not use outside knowledge. Ask for a structured output with an answer field and an evidence field, then check the evidence.
Do not ask for a confidence score as the main safeguard. Ask for the supporting quote; a quote you can verify is worth more than a number you cannot.
RAG and chunking
If retrieval fails, the model cannot be grounded. Test retrieval separately: is the right chunk in the top 3 results? Reduce chunk size if the fragments mix topics, increase overlap if sentences are cut, and add metadata (file, page, section). Raise the context window to 8192 or more, and check that the model still fits in VRAM. Hybrid search and reranking help when the vocabulary of the question differs from the document.
Temperature and model choice
For factual answers, use a low temperature (0 to 0.3). It reduces variation, not the tendency to invent. Choose a model that follows instructions and handles the language of your documents; test two or three instead of assuming that the largest is the most truthful. A reasoning model can help with multi-step questions and can also build a convincing wrong chain.
Logging and periodic review
Keep a log with the date, model, version, quantisation, prompt, retrieved chunks, answer, citations and your verdict. When the model, the documents or the chunking change, rerun the test set. A pipeline that was grounded last month can fail after an update or a new PDF.
Automated tools can help: RAGAS (Apache 2.0), DeepEval (Apache 2.0) and TruLens (MIT) compute grounding and citation metrics, and Promptfoo (MIT) runs repeatable test suites. They are useful for scale, but they also use a model to judge another model. Keep a human review of a sample; the judge can be wrong in the same direction as the model.
If you want the pipeline this method assumes, start with our local RAG guide. It covers chunking, embeddings, citations and the context-length trap; this article is the test you run after mounting it.
Keep reading
- Local RAG with Ollama — documents, chunks, citations and evaluation.
- GGUF quantization explained — what Q4, Q5 and Q8 change.
- Ollama commands cheat sheet — inspect models and runs.
- From ChatGPT to local AI — what to move and what to keep in the cloud.
Sources and date: the context-length behaviour of Ollama and the RAG settings were checked in the Ollama and Open WebUI documentation on 5 November 2026; the licences of RAGAS, DeepEval, TruLens and Promptfoo were checked on their repositories on the same date. The method uses counts from your own test set; no benchmark scores or accuracy figures are claimed here because they depend on the documents, the model and the questions.