Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesAI Engineering with PythonModule 3 · RAG (Retrieval-Augmented Generation)Citations and groundednesswrite40 / 105
+100 XP
Task
📝 **Question:** Pretend an LLM judge has already annotated each sentence with the source chunk that supports it (or \`None\` for unsupported). **Write the function** \`groundedness_score(annotated_sentences)\` that returns \`(percent_grounded, hallucinations)\`: - \`percent_grounded\` — share of sentences with a non-None source, rounded to **one decimal**. - \`hallucinations\` — list of the unsourced sentence \`text\` strings. Then run the gate on this 5-sentence answer and print the report: \`\`\` Grounded: 60.0% Hallucinations: 2 - You will get $500 in store credit. - Same-day refunds are guaranteed. FLAG for human review \`\`\` Threshold: \`>= 90.0\` → \`SHIP\`, otherwise \`FLAG for human review\`. 60% means 3 of 5 sentences are grounded — two are hallucinations the model invented. In production this gate is the difference between "occasional hallucination" and a regulator-visible incident. 📋 Pick the right answer. 💡 **Hint:** Re-read the theory above if unsure.
✏️ Write your code here
🐍
Loading Python...
One-time download (~1 MB). Then it runs instantly.
📊 Result
Press Run to see result...

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…