Skip to main content

Why do language models hallucinate, and how do you reduce it in an app?

LLM and transformer basics · Beginner 1

Short answer

A model generates likely text, not checked facts, so when it lacks the right information it can produce a confident, plausible answer that is false. In an app you reduce this by giving it the right source text (RAG), asking it to cite and to say when it does not know, and checking outputs.

Deeper answer

Hallucination is a side effect of how models work: they are trained to continue text fluently, and nothing in plain generation checks claims against reality. Gaps in training data, questions about recent events, and very specific details such as citations, numbers and names are where it shows most.

Practical defences: ground answers in retrieved documents and instruct the model to answer only from them; allow and reward "I don't know"; ask for citations and verify that cited text exists; use structured output so code can validate fields; and measure hallucination rate on a test set so you know whether a change helped.

What a strong answer covers

Answer it out loud in the mock interview about 1 min

Follow-ups to expect

Common mistakes

Learn it

Use a chat assistant for a real task and check the answer

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.