Why a model invents a contract clause, in four LLM concepts
Telling a model “don’t make things up” sometimes works, but only knowing what it saw and how it picks words explains why, and what to fix.
In brief
- An LLM generates one token at a time from the prompt and what it has just written. It does not look facts up.
- Everything in a request takes up space in the context window, and a longer context can make the model less accurate (context rot).
- Models fabricate partly because training and evaluation reward guessing over admitting uncertainty, so systems must be designed to make “I don’t know” a valid answer.
On the third demo at an insurance company, the head of legal asks the internal assistant about the deadline for filing a claim. The model answers fluently and even cites “Clause 14.3”. The documents the client supplied contain no Clause 14.3. The scenario is hypothetical, but any team that has shipped an assistant will recognize it.
Many engineers respond by adding “don’t make things up” to the prompt and running it again. Sometimes that works, but without knowing why it worked, there is no trail to follow when the error returns the following week.
An FDE needs to answer a harder question: what did the model see, how was it configured to choose its words, and why did it guess instead of saying “I don’t know”?
Four concepts, tokens, the context window, temperature and hallucination, make up the toolkit for diagnosing that failure. This guide explains each one in the order you would use them when debugging on a client site.
The model does not look things up; it keeps writing
The Hugging Face Transformers documentation describes LLMs this way: the model is trained to generate the next token, given the initial text (the prompt) along with what it has itself just generated.
This has to come first, because “Clause 14.3” was not retrieved from any database. The model wrote “Clause”, then saw that “Clause” is usually followed by a number, then a period, then another number. To the model the sequence sounds entirely plausible; whether it is true is something it never checks.
How the model chooses the next token is a parameter you control. The default for the generate() function in Transformers is greedy search, which always picks the most probable token. That suits tasks that must stay close to the input, such as translation or transcription, but works poorly for creative tasks.
Sampling produces more varied output, and temperature determines how unpredictable the chosen token is.
Hugging Face suggests a temperature above 0.8 for creative tasks and below 0.4 for tasks that require tight reasoning. Temperature only takes effect when sampling is enabled. A policy lookup assistant running at a high temperature takes on extra risk for no benefit.
The context window is a desk, not a library
The Claude API documentation defines the context window as all the text a model can refer to when generating a response, including the response itself. It is working memory, quite distinct from training data. Whatever is not on this desk, the model can only half-remember from training, or guess.
What newcomers tend to underestimate is how much sits on the desk. According to the same documentation, everything in a request takes up space: the system prompt, every entry in messages (including tool results, images and documents), the tool definitions, and the model’s output.
In a multi-turn conversation, the output of one turn becomes the input of the next, so the history keeps growing until it hits the limit.
At that point, the reflex of adding more documents to be safe backfires. The Claude documentation is explicit: as the number of tokens grows, accuracy and recall decline, a phenomenon called context rot. A bigger context does not automatically produce better results, so choosing what goes in is a genuine engineering decision.
Dissecting the “Clause 14.3” case
Back to the insurer. The first step is to log the exact request that was sent, not just the user’s question. Then count the tokens in each part with the token counting API, which the Claude documentation recommends for estimating before sending.
The trick is to count several times, adding one component each time, and take the differences to see how much each part uses:
import anthropic
client = anthropic.Anthropic()
MODEL = "YOUR_PROJECT_MODEL" # replace with the model the project uses
def count(messages, tools=None):
kw = dict(model=MODEL, system=SYSTEM, messages=messages)
if tools:
kw["tools"] = tools
return client.messages.count_tokens(**kw).input_tokens
question = {"role": "user", "content": QUESTION}
question_with_docs = {"role": "user", "content": DOCS + QUESTION}
base = count([question])
with_tools = count([question], TOOLS)
with_history = count(HISTORY + [question], TOOLS)
full = count(HISTORY + [question_with_docs], TOOLS)
print("system + question: ", base)
print("tool definitions: ", with_tools - base)
print("conversation history:", with_history - with_tools)
print("retrieved documents: ", full - with_history)
print("total input: ", full)
Suppose that in this case the output looks like this (illustrative figures):
system + question: 1850
tool definitions: 3200
conversation history: 41600
retrieved documents: 2400
total input: 49050
Reading the table: the history from the previous twenty demo turns takes 41,600 of the 49,050 tokens, more than 84% of the budget. The three passages returned by the retrieval step take only 2,400 tokens, and on inspection none of them mentions the claim deadline.
That gives two suspects: the information needed was never on the desk, while most of the desk was taken up by irrelevant history.
Next, open the configuration file. If the assistant is running at a temperature of 0.9 because someone copied it from a marketing-email demo, that is the third suspect. All three are fixable with ordinary engineering: trim the history, repair retrieval and lower the temperature.
Even with all three fixed, one question remains: why didn’t the model simply say the documents lacked this information?
Why models prefer guessing to saying “I don’t know”
The paper “Why Language Models Hallucinate” by Kalai, Nachum, Vempala and Zhang gives a fairly blunt answer. According to the authors, training and evaluation procedures reward guessing rather than acknowledging uncertainty.
Models are optimized to be good test-takers, and on a test, guessing when unsure still helps the score.
They also argue that hallucinations are nothing mysterious: they originate as ordinary errors in binary classification, that is, failing to tell a true statement from a false one. That makes the FDE’s job on a client site fairly clear.
If your eval suite scores only “correct answer” and treats “I don’t know” as wrong, you are reproducing the very incentive that makes the model guess.
The sensible approach is to make “not in the documents” a valid answer at both ends. In the prompt, state clearly that the model may decline and must name the clause it is relying on. In the eval, include questions that deliberately have no answer, and give high marks to a well-timed refusal.
Common mistakes
The most common mistake is treating the context window like a hard drive and stuffing in as much as possible, when it is working memory that degrades when overfilled. The second is forgetting that tool definitions and output also take up space, so a request that runs fine in a three-turn demo breaks when a real user reaches turn thirty.
The third is setting temperature by feel or copying it from another project. The fourth is the hardest to spot: building an eval suite that counts only correct answers, so it neither catches nor prevents answers that are confident but fabricated.
All four can be avoided by debugging in the order shown in the diagram: what is on the desk first, decoding parameters next, how the system rewards guessing last, and then turning the failure into a test case so it does not quietly return.
That process, rather than a line saying “proficient in prompt engineering”, is what belongs on a CV, for instance: “reduced fabricated answers using evals with unanswerable questions and a per-component token budget”.
Clients will not remember how you explained what a token is. They will remember the time their assistant answered “the available documents do not specify this deadline” instead of inventing Clause 14.3, and that is when they start to trust the system.
Was this article useful?
Thanks for the feedback!