CourseRetrieval-Augmented Generation: The Complete Course · Module 9: Generation, Grounding, and Citations · part 64 of 95
Part 64 · Module 9: Generation, Grounding, and Citations

Lab: The answer step, guarded and checked

64 min read·13 Oct 2026
Module 9 · Lab · About 75 minutes · Needs: lessons 1 to 4 of this module, the Module 6 and 8 labs (or the cells in Step 1), and a free Groq or Gemini key

What you are building

ELLIE'S QUESTION THROUGH THE ANSWER STEP 3 documents from Module 8 respond() answer.py guard.py trust grounding rules, NLI send checked claims hand over with reasons
One function, respond(), runs the guard (blue) and the grounding checks on every draft: a fully checked answer is sent (green), anything else goes to a person with reasons (amber).

On Friday 9 October Ellie asks whether her repeated E7 fault is covered. Module 8's context assembler sends three documents to the answer step; a bigger budget would also send the forum post with the injected instruction. This lab turns the module's four lessons into three package files. hollin/guard.py marks untrusted text, keeps it last and checks every address and every document's scope. hollin/answer.py holds the system prompt, the answer form and its contract, and respond(), which runs every check in order. hollin/grounding.py holds the checks that read meaning: rules and a local NLI model. Then you replay the attacks with a scripted model, write tests that need no key, and commit. The real model is called twice, in Step 5.

The rest of this course is yours to keep

This course is bought on its own, once, and stays readable afterwards, including the parts added to it later.