← Lesson
Hallucinations
Joeven
Run
Reset
Python loads on first run
def citations(answer, allowed): return [c for c in allowed if c in answer] def amounts_grounded(answer, sources): blob = " ".join(sources) for token in answer.replace(".", " ").split(): if token.startswith("$") and token[1:].isdigit(): if token not in blob: return False return True def claimed_tool_without_trace(answer, tool_roles): return "called get_job" in answer.lower() and "tool" not in tool_roles allowed = ["doc_12", "tool_get_job"] answer = "Job 17 failed (tool_get_job). Refunds take $5 according to policy. I called get_job." sources = ["status=failed", "Refunds take 5-7 days"] print("citations", citations(answer, allowed)) print("amounts grounded", amounts_grounded(answer, sources)) print("fake action?", claimed_tool_without_trace(answer, ["assistant"]))
Run to execute this in your browser. Nothing is sent to a server.