Course map
Stage 1: Foundations
Stage 2: Machine Learning
Stage 3: Deep Learning
Stage 4: LLMs & Generative AI
Stage 5: Production & Specialization

Part 17 / Topic 3 of 6

Grounded prompts

Retrieval found the passages; the prompt must force the model to stay inside them. Part 15's shape, deployed:

# examples/02_a_complete_rag_call_retrieve_ground.py (ran against the local mock)
system="Answer only from the documents. Cite doc ids in [brackets]. "
       "If the documents do not answer the question, say so."
messages=[{"role": "user", "content": f"<documents>\n{context}\n</documents>\n\n{question}"}]
# retrieved: ['returns', 'damaged'] <- real retrieval, real doc ids
# answer: [mock reply] <- placeholder: this run used the local mock

The three grounding rules each kill a failure mode: only from the documents (no outside knowledge sneaking in), cite ids (verifiability), say so when unanswerable (no confident inventions). The retrieval above is real; only the generation is mocked in this offline run.

🧪 Quick quiz

  1. Why ask the model to cite document ids?
Show the answer

So answers can be checked against sources and unsupported claims spotted — citations make grounded answers verifiable.

Done here? The practice set for Part 17 — 4 exercises with solutions — is on the part page.

Search the guide