NEWCloud agents are live.See how

Models

Hallucination

Output that is fluent, confident, and false: an invented API, a library that does not exist, a citation to a page that was never written. Language models generate plausible continuations rather than looking facts up, so hallucination is a property of how they work, not an occasional bug; verification is the only defense.

At a glance

Cause
Next-token prediction with no lookup
Common in code
Invented methods, packages, flags
Most likely on
Rare, recent or private APIs
Best defense
Compilers, tests and real docs in context
Not the same as
A logic bug in real code

How it works

A model writes one token at a time, each chosen because it is a likely continuation of everything before it. Nothing in that loop consults a source of truth. If a library has a method called getUserById, a sibling called getUsersByIds looks just as plausible, and the model has no internal signal that separates the real one from the guess.

That is why hallucinations cluster around the long tail: a package's newer API, a CLI flag added last year, an internal helper in your own repo the model has never seen. The less often something appeared in training data, the more the model fills the gap with a pattern that merely looks right.

Why it matters

In coding work the common forms are an import from a package that does not exist, a function called with arguments it never accepted, a config key the tool silently ignores, and a confident report that tests passed when they were never run. The last one is the most expensive, because it reads as a status update rather than as code you would think to check.

Invented package names carry a security risk too: if an agent keeps suggesting the same nonexistent package, someone can publish a malicious one under that name and wait. What actually helps is giving the agent ways to be checked. An agent that can run tsc and the test suite sees the missing method and corrects itself before you read the diff, and putting the real docs or source into context removes the gap it would otherwise fill.

Hallucination versus a plain bug

A bug is wrong logic built from real parts: an off-by-one, a missed null check. A hallucination is a fabricated part: the method, the file or the fact never existed. Bugs hide in logic you have to trace, while hallucinations usually fail loudly the moment something compiles, imports or runs, which is why automated checks catch most of them.

Common mistakes

  1. Asking the model to double-check itself instead of letting it run the compiler and tests.
  2. Accepting an agent's claim that tests passed without seeing the command output.
  3. Installing a dependency an agent suggested without confirming the package exists and is maintained.

Frequently asked questions

Can hallucinations be eliminated completely?

No. They follow from how language models generate text, so the practical goal is to catch them with tests, type checks and review rather than to prevent every one.

Do newer models hallucinate less?

Generally yes on common knowledge, but every model still invents details about obscure, recent or private code it has not seen. Grounding it in real files and docs helps more than switching models.

How do I stop an agent from inventing APIs?

Put the real documentation or source in its context, and let it run the compiler and tests so a fabricated call fails immediately instead of reaching review.

Sources

Know the words. Run the work.