Grounding Prompts in Sources

Updated · 5 min read
mediumPython 3.13aipromptsgroundinghallucinationsprompt-engineeringinterview

How do you stop a model from making things up about your own documents? Advitha is researching a letter from 1915 for a history project. When she asks a chat assistant about it from memory, it gives a confident answer that turns out to be wrong. When she pastes the letter in and asks it to answer only from that text, with a quote, the answer is right and easy to check.

That is a grounded prompt. This lesson shows how to write one.

What Grounding Means

Grounding means giving the model the source material and telling it to answer only from that source. Instead of relying on what it learned in training, which may be missing or wrong, the model reads your document as context.

Answer only from the source, with a quote

A Grounded Prompt Template

text
Answer the question using only the document below.
Quote the exact sentence that supports your answer.
If the document does not contain the answer, reply: "Not stated in the document."
 
Question: Why was the money returned?
 
Document:
"""
[paste the document here]
"""
PartWhy it matters
"Using only the document"Keeps the model from adding facts from memory
"Quote the exact sentence"Lets you verify the answer in seconds
"If it doesn't say, reply..."Gives the model an honest way out instead of guessing
Clear markers around the documentSeparates your instructions from the pasted text

Grounding is the core idea behind retrieval-augmented generation (RAG), where an app finds the right documents automatically and adds them to the prompt; a later chapter builds one.

Common Mistakes

Asking about a document without pasting it. The model will answer from memory, or invent.

Leaving out the "not stated" option. The model may stretch the text to give some answer.

Pasting instructions inside the document. Text inside a document can contain instructions that try to change the model's behavior; keep your instructions outside the markers, and treat document text as data.

Interview Corner

What is a grounded prompt?

A prompt that supplies the source material and instructs the model to answer only from it, ideally with quotes and an explicit "not stated" option. It reduces hallucinations and makes answers verifiable.

How does grounding relate to RAG?

RAG automates grounding: it retrieves the most relevant documents for a question and adds them to the prompt, so the model answers from those sources.

Practice

Exercise: ground a real document. Take a document you know well, such as a policy, a manual page or a long email. Ask three questions without pasting it, then three with a grounded prompt. How many answers changed, and how many quotes matched the document exactly? Then ask one question the document can't answer, and check that the model says so.

Check your understanding:

  1. What does grounding mean?
  2. Why ask for a quote?
  3. Why include a "not stated" option?

Quick check: grounded prompts

4 questions
1What is grounding?
2Why ask the model to quote the source?
3What should the model say if the document doesn't contain the answer?
4What is RAG?

Key Takeaways

Quick reference

TermMeaning
GroundingAnswering from supplied sources instead of memory
Grounded promptA prompt with the source, "only from the source" and a quote request
RAGRetrieval-augmented generation: retrieving sources to ground answers

Was this tutorial helpful?

Lesson 39 of 186