Skip to main content
← CoursesAI Engineering with PythonModule 3 · RAG (Retrieval-Augmented Generation)Citations and groundednesswrite39 / 101
💬 Discuss🧪 Playground+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.

Keep going

✏️ Write your code here
🐍
Loading Python...
First visit only — ~5-10s. Stays cached afterward.
📊 Result
Press Run to see result...
📣 Help someone learn PythonShare this lesson with a friend — the first 15 are free, no signup.Tweet

💬 Discussion

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