Hallucinations and grounding
Models sometimes state things that are fluent, confident and false. See why a hotel bot invents a checkout time, and how grounding it in real documents fixes the answer.
9 minFree
- Ask
- Retrieve
- Generate
- Made up
- Grounded answer
Press Play to watch it run, or step through with ← →. Then switch to Practice and run it yourself.
Conversation
No messages yet. Press Play.
Background: the idea in plain words
Sometimes a model tells you something false in a perfectly confident voice. That is a real problem when a customer acts on the answer.
A hallucination is an answer that sounds right but isn't: a made-up date, a wrong policy, a link to a web page that never existed. Google Cloud lists causes such as gaps or flaws in training data and a lack of grounding: the model has no connection to the real facts it's being asked about.
It helps to remember what an LLM (large language model) does (see What is an LLM?). It predicts the most likely next token (a small piece of text). When the true answer isn't in its training data or its prompt (the text you send it), the most likely-sounding text still comes out, and it sounds just as confident as a correct answer. The model doesn't check facts unless you give it facts to use.
A tiny example. A guest asks a hotel's chat bot "What time is checkout?" The model has never seen this hotel's rules. Many hotels say 12 noon, so it answers "12 noon". The real policy says 11 am.
The fix is grounding: put trusted information into the prompt and tell the model to answer from it. When the information comes from searching your own documents, this pattern is called retrieval-augmented generation (RAG).
Step by step, a grounded bot works like this. First it searches your documents for a passage that matches the question. Then it puts that passage into the prompt. Then it tells the model to answer only from the passage, and to say so when the answer is not there.
Press Play to see the hotel bot guess. Then switch Try it to Grounded in your documents, and then to Not in the documents: say so.
What to notice
- Confidence tells you nothing. The wrong answer and the right answer sound equally sure. You can't spot a hallucination from the tone.
- Asking again doesn't ground anything. "Are you sure?" adds no new facts to the context, so the model may repeat or defend its guess.
- Grounding changes what's most likely. With the policy passage in the prompt, copying the fact becomes the most likely continuation. The model hasn't become smarter; it has better context.
- Citations make answers checkable. An answer that points to "stay policy §4" can be verified by a person or an automated check.
- Permission to say "I don't know" is a feature. Tell the model what to do when the sources don't cover the question, such as hand over to a person. Otherwise it will often fill the gap.
Go deeperGrounding with Google Search
For public, up-to-date facts, the Gemini API can ground answers in Google Search. You enable the google_search tool, and the model decides whether a search would help, writes and runs the queries, and answers with citations. The Gemini docs list the goals as factual accuracy (reducing hallucinations), real-time information, and citations that show the sources for the model's claims. In the response, each citation links a span of the answer to a source URL and title.
Your documents (RAG)
Private, company-specific facts: policies, product manuals, order data. You control what's searchable.
Google Search grounding
Public, changing facts: news, prices, opening hours, recent events. Results come with web citations.
Grounding reduces, it doesn't remove A model can still misread a passage or combine two sources wrongly. For anything that matters (money, health, legal terms), show the source to the user and test your bot on questions whose answers you know.
Go deeperWords to know
| Word | Meaning in simple words |
|---|---|
| Hallucination | An answer that sounds right but is false or made up |
| Grounding | Tying the answer to trusted information that you put into the prompt |
| RAG | Retrieval-augmented generation: search your own documents first, then answer from what was found |
| Retriever | The part of your app that searches your documents for matching passages |
| Citation | A pointer to the source of a claim, so a person can check it |
Check your understanding
Sources: the official documentation
This lesson is based on the official documentation. Check it for the latest details.
Something wrong or unclear in this lesson? Tell us, it gets fixed.