← Lesson
Self-Check
Joeven
Run
Reset
Python loads on first run
def check(answer, context, allowed_ids): fails = [] for tok in answer.replace(".", " ").replace("(", " ").replace(")", " ").split(): if tok.startswith("$") and tok[1:].isdigit() and tok not in context: fails.append("amount " + tok) if tok.startswith("doc_") and tok not in allowed_ids: fails.append("id " + tok) return fails ctx = "Refunds take 5-7 days. Job 17 failed." allowed = {"doc_policy", "tool_get_job"} print("grounded", check("failed (tool_get_job) in 5-7 days", ctx, allowed) or "ok") print("bad", check("refund $5 today (doc_99)", ctx, allowed)) print("are you sure would not catch $5")
Run to execute this in your browser. Nothing is sent to a server.