Tutorials / Prompt Engineering with ChatGPT / Avoiding hallucinations and checking facts

Avoiding hallucinations and checking facts

15 min read text
Course contents (19 lessons)
  1. Understanding the tool
  2. What a language model is, in plain words
  3. How ChatGPT works from a user's point of view
  4. Building a good prompt
  5. The anatomy of a good prompt
  6. Being specific: how to remove guesswork
  7. Showing examples: few-shot prompting
  8. Asking for step-by-step reasoning
  9. Controlling and improving answers
  10. Controlling length, tone and format
  11. Iterating: how to improve an answer with follow-ups
  12. Custom instructions and memory
  13. Working with files and images
  14. ChatGPT for real tasks
  15. Using ChatGPT for writing: emails, reports and rewrites
  16. Using ChatGPT for studying and learning
  17. Using ChatGPT for coding and technical work
  18. Using ChatGPT for data, spreadsheets and business tasks
  19. Prompt templates
  20. A library of reusable prompt templates
  21. Reliable and safe use
  22. Avoiding hallucinations and checking facts
  23. Privacy and safe use
  24. Workflows and final project
  25. Building repeatable workflows and custom assistants
  26. Final project: build your own prompt toolkit

What a hallucination is

A hallucination is when the model states something false in a confident and fluent way. It may invent a book that does not exist, attribute a quote to the wrong person, give a wrong date, or describe a function that your software does not have. It is not a rare bug that will vanish next year. It follows from how these systems work: they produce likely-looking text, and likely-looking text is not the same as true text.

It is most likely when the answer is obscure, very specific (exact numbers, citations, legal clause numbers), recent, or when your question assumes something false. A model asked "Why did the 1995 Lahore tram strike fail?" may well give a detailed answer even if there was no such strike. The question made the story feel real.

Prompts that lower the risk

You cannot remove the risk, but you can reduce it.

1. Give it the source

Answer the question using only the text below. If the text does not
contain the answer, say "The text does not say." Quote the sentence you
used.

Text: [paste]

Question: What is the refund period?

This is the strongest method. The model is working from a document you control, and the quote lets you verify it in ten seconds.

2. Allow "I don't know"

Answer the question below. If you are not sure, or if the answer may
have changed recently, say so clearly. Mark each claim as "confident",
"probably" or "not sure".

Question: What is the current standard rate for [a tax or fee]?

These labels are not perfectly reliable, because the model can feel confident and be wrong. But they do shift behaviour, and the "may have changed" idea nudges you to look up current figures.

3. Do not feed it false assumptions

Ask neutral questions. "What are the pros and cons of X?" is safer than "Why is X better than Y?" which assumes it is. If you are unsure that something exists, ask "Is there a ... ? If not, say so."

4. Ask for reasoning you can inspect

Before giving your final answer, list the key facts you are relying on.
Then mark which of them I should verify independently.

A checking routine

Match the amount of checking to the cost of being wrong. A joke needs none. A school essay needs some. A medical, legal or financial decision needs a lot and a qualified person.

Type of claimHow to check
Names, dates, placesSearch for them in an official or well-known source
Numbers and statisticsFind the original report; recalculate sums yourself
QuotesSearch for the exact words with the person's name; many are invented or misattributed
Citations and linksOpen them. If you cannot find the book or paper in a library catalogue or a search, treat it as made up
Laws, rules, pricesGo to the official source; they change and differ by country
CodeRun it, and read the official documentation for any unfamiliar function

Use a second pass

You can ask the model to audit its own answer, which finds some errors, not all.

Re-read your previous answer as a fact-checker. List every specific
claim (names, numbers, dates, quotes, sources). For each, say how sure
you are and how I could check it. Flag any claim that might be invented.

This is useful as a to-do list for your own checking. Do not treat "I reviewed it and it is fine" as proof. The same system that made the error may repeat it.

Using tools that look things up

If your version can search the web, it may be able to show where information came from. Ask for it:

Search for the current information on this and give me links to the
sources you used. For each key claim, say which source it came from.
If the sources disagree, tell me.

Then open the links. A cited answer is more checkable, but the model can still misread a page or attach a claim to the wrong source. Treat the link as the thing to confirm, not the model's summary of it. Which tools exist and how well they work depends on your version, so look at what is on your screen.

A short case study

I once asked an assistant for three academic papers on a niche topic. It gave me three neat references with authors, years and journal names. Two of them could not be found anywhere. The third existed but was about something different. Nothing in the tone of the answer warned me. Since then my rule is simple: a reference I have not opened does not exist. That rule would have saved me embarrassment if I had followed it that day.

The common mistake

Judging an answer by how polished it sounds. A tidy list of facts feels more reliable than a messy one, even though polish says nothing about truth. The second mistake is checking only the claims that seem surprising. Plausible errors, such as an off-by-one year, slip through more easily than wild ones. Check the details that your work depends on, even if they look ordinary.

Try it yourself

  1. Ask a question about a small local topic you know well, such as your street, school or company. Mark each claim right or wrong. This calibrates your sense of how much to trust.
  2. Ask for three sources on a topic and try to find each one yourself.
  3. Use the "answer only from the text" prompt with a paragraph, and ask a question the paragraph cannot answer. See whether it says "The text does not say".
text
Answer the question using only the text below. If the text does not
contain the answer, say "The text does not say." Quote the sentence you
used.

Text: [paste]

Question: What is the refund period?

This course is free to read. Create a free account to enrol, save your progress and pick up where you left off.

Sign up free I already have an account