QuiddityML

By · 25 November 2026 · 6 min read

Why LLMs hallucinate, and their other failure modes

Where hallucination, memorized text and inherited bias come from in a large language model, and what to test before you put one in a product.

A hallucination is text from a large language model (LLM) that states something false or unsupported, written just as fluently as a true answer. It is a natural result of how these models are trained, not a rare bug. The same training also explains the other common failures: repeating private or copyrighted text, copying the slants of its training data, and answers that change when a prompt is reworded.

An LLM is a neural network trained to predict the next token of text, where a token is a whole word or a piece of a word. The examples below sometimes say "word" to keep them simple.

How an LLM learns in the first place

During pretraining, the model reads a huge collection of text called a corpus. It learns to predict each next token from the tokens before it. Nobody labels this data by hand. The text itself supplies the answer to every prediction, so this kind of training is called self-supervised. The model that comes out of this stage is called a base model.

The base model picks up grammar, facts and patterns of reasoning because they help it predict the corpus. Each failure in this post comes from that same process. The model learns whatever patterns help prediction, including false ones, biased ones and ones copied word for word.

Why LLMs hallucinate

What the model learns is real, but it is statistical and lossy. It stores patterns about what usually comes next, not a table of checked facts. For any prompt it predicts a probability for every possible next token, and nothing in that step checks whether the most likely continuation is true.

Compare a database with a language model. A database returns the record stored under a key, so a question about the tallest mountain returns "Everest" if that is what the record holds. A language model returns probabilities, and if its training text made a wrong answer look likely, the wrong answer comes out first.

A database returns stored records by key, while a language model gives each candidate answer a probability. For the tallest mountain its top answer is K2 at 0.51, so it answers fluently and wrongly.

The code below uses the probabilities from that last chart. The model's probabilities for the next token after "The tallest mountain is" put K2 first. Picking the most likely token, called greedy decoding, returns K2 every time. Sampling from the probabilities returns K2 about half the time and the right answer about a fifth of the time.

1import torch
2 
3torch.manual_seed(0)
4candidates = ["K2", "Everest", "Kilimanjaro", "Denali"]
5probs = torch.tensor([0.51, 0.22, 0.16, 0.11])  # next-token probabilities after "The tallest mountain is"
6 
7greedy = candidates[probs.argmax()]
8samples = torch.multinomial(probs, num_samples=1000, replacement=True)
9counts = torch.bincount(samples, minlength=len(candidates))
10 
11print("greedy answer:", greedy)
12for name, c in zip(candidates, counts):
13    print(f"{name:12s} {c.item()} of 1000 samples")
1greedy answer: K2
2K2           514 of 1000 samples
3Everest      223 of 1000 samples
4Kilimanjaro  142 of 1000 samples
5Denali       121 of 1000 samples

Neither way of choosing a token looks the answer up anywhere. The sentence that comes out reads the same whether it is right or wrong.

Hallucination also happens when the model fills a gap. Ask it to cite a paper on a topic and name the authors, and it can produce a title and author list with the right shape that matches no real paper. Citations are a common example because the format is easy to predict and the details are not.

A prompt asks for a paper on scaling and its authors. The LLM outputs "Paper Z, Author 7 and Author 8, 2022", which appears nowhere in the checked reference list.

Memorization and regurgitation

Training rewards prediction. A passage that appears many times or one that is unusual can leave traces in the model's weights. The model may then repeat that passage word for word, called regurgitation. It is most likely when a prompt starts close to the memorized text.

That creates copyright, privacy and security problems. Internet-scale corpora can contain licensed books, copied articles, personal details and leaked passwords. The model does not keep a link to the document each token came from, so its output carries no sign that it was copied.

One training document contains the sentence "the harbour bell rang twice at dusk and once again before dawn." A prompt starting with "the harbour bell rang" makes the model repeat that exact span in its output.

Bias in, bias out

A web-scale corpus is not a balanced sample of human writing. Some groups and languages appear far more often than others. The same goes for dialects, jobs and opinions, and some appear mostly through stereotypes. If "engineer" sits next to "he" much more often than next to "she", predicting the corpus well means learning that pairing.

The model carries those patterns into the products built on it. Without checks, the same slant can show up in summaries, rankings and generated examples. A classifier that labels people's roles can repeat it too.

Counts in the pretraining corpus pair "he" with engineer and CEO, and "she" with nurse and teacher. The LLM passes the same pattern into summaries, labels, assistant answers and rankings.

Prompt sensitivity

LLMs can do a new task from a few examples placed in the prompt, with no further training. This is called in-context learning, and it is brittle. Change the wording, the order of the examples or the labels, and the probabilities the model assigns to its answers can move a lot.

The chart below shows the same model scoring the same review three times. Only the prompt around it changed, and the probability of "positive" went from 0.68 to 0.46.

Three prompts for the same sentiment question differ only in label order, example order or wording. The same weights give P(positive) of 0.68, 0.51 and 0.46.

Prompting still works. A prompt that looked good on a few hand-picked inputs needs testing on many realistic ones before anyone relies on it.

The evaluation gap

A low validation loss, a strong benchmark score and a product that behaves well are three different claims. Validation loss says the model predicts held-out text better on average. A benchmark score says it did well on one dataset under one scoring rule. A product needs good behavior on the inputs people actually send, which neither number measures.

Validation loss can look good and a benchmark score fair while product behavior is poor. An LLM system gets evaluated on task accuracy, factuality, bias, refusals, latency, cost and monitoring.

Evaluating an LLM system usually covers task accuracy, factuality and bias. It also covers refusals, latency, cost and monitoring after launch.

One base model, many inherited flaws

Many products are built on the same few base models. A model trained once on broad data and then reused for many tasks is called a foundation model. Sharing one base spreads its strengths, and it also spreads its blind spots. A bias or failure in the base can appear in a search tool, a tutor, a summarizer and a coding tool at once. This risk is called homogenization.

One foundation model feeds search, chat, a classifier, a tutor, a summarizer and a coding tool, and its warning sign appears in every one of them.

The same mechanism creates all of these

Put the pieces side by side and they share one cause. Pretraining learns the patterns in its corpus whether they are true or false. That includes biased, private and copyrighted text. Scaling the model up makes its output more fluent without making it more trustworthy.

A broad corpus goes through self-supervised pretraining into a base LLM, then adaptation and fluent output. False patterns, bias, private text and copyrighted text in the corpus come out as hallucination, regurgitation, biased answers and brittle prompts.

What reduces these failures

Pretraining gives a base model broad skill with text. It does not by itself make the model follow instructions or tell the truth. It also does not teach it to refuse unsafe requests, cite sources or match a product's tone. That is why modern LLM work adds more steps after pretraining. Common ones are training on written example answers and training on human preferences between answers. Others retrieve documents to answer from, give the model tools, filter its outputs or run evaluation loops.

A raw pretrained model is fluent, broad and lossy. Supervised data, preferences, retrieval, tools and tests are added on top, aiming at checked accuracy, aligned values, measured refusals, traceable answers and incorporated preferences.

These steps reduce some failures without removing them, so a few mistakes are worth avoiding:

Hallucination is one symptom of a model trained only to predict text. Getting from a base model to an assistant takes post-training, covered in pretraining vs post-training. Its first step is supervised fine-tuning on written example answers, covered in instruction tuning and SFT explained. How pretraining itself works is covered in how do LLMs work?

QuiddityML teaches LLM failure modes as their own concept in the Intro to NLP track, with exercises on why a model states a false fact with full confidence and on putting the checks for an LLM feature in order before it ships.