LyraLearn AI Learning Platform
Exams
← Module 3 Β· Prompt Engineering
🎧 Listen

Grounding and Context Injection

Grounding is the single most important technique in applied AI: instead of trusting the model's memory, you retrieve the relevant facts and place them in the prompt, then instruct the model to answer only from those facts. It is the antidote to hallucination and the heart of RAG (which Module 6 covers in full).

A closed-book model guessing from memory is crossed out while a grounded model reads retrieved passages placed in its prompt and answers with citations.

Why grounding works

Recall that a model predicts plausible text from its frozen training. Ask it a factual question cold and it will approximate β€” sometimes right, sometimes confidently wrong. But put the actual source passage in the prompt and the task changes from "remember this" to "read this and answer," which is exactly what models are good at. You convert an unreliable recall task into a reliable reading-comprehension task.

How to inject context well

  1. Retrieve the relevant chunks for the question (vector + keyword search).
  2. Delimit them clearly β€” wrap the context in obvious markers so the model knows where the data starts and ends.
  3. Label them as data, not instructions β€” state explicitly that the context is reference material, never a command to follow (this is also a security control; see the prompt-injection lesson).
  4. Number the sources so the model can cite them: "answer using the context above and cite each claim like [Source 2]."
  5. Cap the size β€” include the relevant context, not everything; more isn't better.

Cite, and grade the evidence

Two practices make a grounded answer trustworthy:

Grounding in practice

This is precisely how the AI Tutor you're using works: your question is embedded, the closest lesson passages are retrieved from SQL Server, the evidence is graded, and only then is the model asked to answer from those passages with citations. If you ask it something the lessons don't cover, it tells you it doesn't know β€” that refusal is grounding doing its job.

🧠 Quiz yourself on this lesson →

Ask the AI Tutor

Grounded in the course lessons β€” it cites its sources and says when it doesn't know.