Back to Blog
June 2, 20268 minutes

Why AI Lies with Confidence: The Sampling Parameter Myth

I just watched an AI confidently assert the wrong platform name seconds after reading the correct one. Here's why temperature and top-k wouldn't have saved me — and what actually might.

aillmhallucinationagent-architecturesystems-thinking

TL;DR: I told an AI agent my deployment platform was Cloudflare Workers. Minutes later it said Cloudflare Pages. The correct information was in its context window the whole time. Temperature and top-k don't fix this because the problem isn't randomness — it's attention. The fix isn't a sampling parameter. It's an explicit verification loop.


The Incident

I had just finished reviewing a draft blog post with an AI coding agent. The post was about security, agents, and secrets management. In the project documentation, plain as day, it said:

Platform: Cloudflare Workers

The agent had read this file. It was in its context window. There was no ambiguity — not "Cloudflare" generically, but the specific product: Workers.

Minutes later, closing out the session, the agent said: "the next Cloudflare Pages deploy."

I caught it. The agent didn't. When I asked why, we had a conversation that exposed something most people building with LLMs don't understand. The agent explained that "Pages" was statistically more probable than "Workers" in the phrase "next X deploy" because its training data associates blogs and static sites more strongly with Cloudflare Pages.

It had the right answer in memory and chose the wrong one because the wrong one felt more familiar.

This is not a bug. This is architecture.


The Transformer Attention Mechanism: A Soft, Weighted Guess

To understand why this happens, you have to understand how a transformer model "remembers" what it read.

When an LLM processes your prompt, it doesn't have a database of facts it queries. It doesn't have a lookup table where "deployment platform = Workers" gets stored and retrieved on demand. What it has is attention: a soft, weighted sum over every token in the context window. Each token in the output is generated by attending to all previous tokens — both the ones in your prompt and the ones it has already generated — and computing a probability distribution over what comes next.

Think of it like a room full of people shouting suggestions. The model doesn't pick the suggestion from the person who knows the answer. It picks the suggestion that gets the loudest collective response. And the training data — billions of web pages — is a much louder chorus than the single mention of "Workers" in your project file.

At that exact decoding step, the co-occurrence statistics in the model's parameters (blog + deployPages) produced a stronger signal than the distant mention of Workers in a file read minutes earlier. The attention mechanism doesn't have a hard rule that says "if 'Workers' appears in the context, never emit 'Pages'." It computes scores. The familiar won.


Why Temperature and Top-K Don't Save You

This is where most developers get lost. They hear about hallucination and their first question is: "Can't you just turn down the temperature?"

No. Temperature and top-k control which token gets sampled from the probability distribution. They don't control whether the distribution itself is correct.

Temperature redistributes probability mass. At low temperature, the model becomes more deterministic — more rigidly following the highest-probability path. If "Pages" is already the most probable next token, lower temperature makes the model more likely to pick it, not less. You have made the lie more confident.

Top-k limits how many tokens the model considers. At top_k=1 — greedy decoding — the model must pick the single most probable token. If "Pages" > "Workers" in that position, greedy decoding guarantees the wrong answer. A slightly higher top_k might keep "Workers" in the pool, but there's no guarantee it wins the sampling lottery.

Top-p (nucleus sampling) is no better. It filters to the smallest set of tokens whose cumulative probability exceeds a threshold. If "Pages" dominates the probability mass, top-p collapses to nearly-greedy behavior.

Sampling parameters govern which token you pick from your distribution. They don't govern whether your distribution contains the right token in the first place.

This is a critical distinction that separates people who play with LLMs from people who build reliable systems with them.


The Two Layers: Model Behavior vs. Agent Architecture

Here's where it gets useful. The failure I described — confidently asserting the wrong platform — is uncontrollable at the model level but controllable at the agent level. Understanding this distinction is what separates a prototype from a production system.

The Model Level: What You Cannot Fix

A transformer will always compute attention as a soft, weighted sum. It will always be susceptible to prior override — the phenomenon where training-data associations overpower in-context facts. It will always generate tokens probabilistically rather than retrieving them deterministically.

You cannot change this without changing the architecture. You cannot prompt your way out of it. You cannot temperature-your-way out of it. These are fundamental properties of how the model reasons.

The Agent Level: What You Can Control

An agent is not a model. An agent is a system that uses a model as one component among many. And at the system level, you have options:

  • Explicit verification loops: Before emitting a specific claim, the agent re-reads the source material. It doesn't trust its own output.
  • Tool use over recall: Instead of asking the model to remember which platform you use, the agent queries wrangler.toml or the project documentation at generation time.
  • Lower-confidence phrasing: The agent says "the next deploy" instead of naming the platform, or qualifies claims it hasn't verified.
  • Structured output with validation: Generate into a schema, then validate against ground truth before presenting to the user.

The failure in my session was procedural, not architectural. The agent had the capacity to verify and chose not to. It generated fluently and committed to the token.


What This Means for Building with LLMs

If you are building systems that use LLMs — whether that's a coding agent, a support bot, or a content pipeline — you need to internalize this:

Models confabulate specifics. Names, versions, platforms, numbers, file paths. They do this not because they are broken but because they are doing exactly what they were designed to do: generate probable sequences of tokens. The problem is that "probable" and "true" are not the same thing, and the divergence is most dangerous on the specific details that matter most.

The Current State of the Art

There is no fix in a parameter. The current best practice is a layered defence:

  1. Ground the model: Give it access to search, retrieval, and tools rather than expecting it to remember.
  2. Verify before asserting: Any specific claim gets checked against a source of truth before it reaches the user.
  3. Design for fallibility: Build systems where a wrong token is caught by validation, not propagated to production.
  4. Human review for specifics: Never trust an LLM to get a version number, a platform name, or a configuration detail right without checking.

The Bottom Line

I watched an AI confidently assert Cloudflare Pages seconds after reading Cloudflare Workers. When I asked why, it gave me a precise technical explanation about attention mechanisms, probability distributions, and prior override. It understood exactly what it had done and why it had done it. And it would do it again.

That is the nature of the tool. It generates fluently, confidently, and often correctly — but the confidence is not correlated with correctness in the way we intuitively expect. It is correlated with familiarity, with statistical prominence, with what the training data said most often.

The fix is not inside the model. It is in the system you wrap around it. Explicit verification. Tool use. Validation layers. And above all, the humility to treat every specific claim as suspect until proven otherwise.

The model will not stop lying with confidence. Your job is to stop believing it blindly.


About the Author

César Valadez is a software engineer and founder of ValkymIA. He writes about systems, security, and the gap between technical possibility and human reality.

Need help with this topic?

Let's discuss how I can help implement something similar for your project.