🎓 A1Learner
🔍
0 of 50 lessons completed

Prompt Engineering: Hallucination

A hallucination is a confident wrong answer. The model writes it as if it were true.

A question with no answer in the data

There is no first-order code in the ShopStack data. The prompt gives the model nothing true to say, so it may invent one.

What is the discount code for first orders at ShopStack?

The same question, with the facts given

With the fact in the prompt, the model has something true to say. The reply stays honest.

ShopStack has no first-order discount code. A customer asks for the first-order code. Write a short reply that says there is no first-order code.

Example

ShopStack ships within the country only. A customer asks if ShopStack ships to Canada. Write a short reply that says ShopStack ships within the country only.

Key points

  • A hallucination is an answer that sounds true and is not.
  • The model predicts words, not facts. A smooth sentence can still be wrong.
  • The first defence is to ask only for what the prompt gives. Facts in, facts out.
  • A question with no answer in the data invites a guess. A guess becomes a hallucination.

This example runs a prompt with the fact given against the local model and shows the reply it gave.

Note

Confidence is not proof. A certain tone does not mean a true answer.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

What is the first defence against hallucination?