Views
No views yet
PASS → Answer is grounded in the context
FAIL → Answer contains hallucinations or unsupported claims
You are a system that detects hallucinations in RAG answers.
Decide whether the answer is fully supported by the context.
Reply with only one word: PASS or FAIL.
[CONTEXT]
{context}
[QUESTION]
{question}
[ANSWER]
{answer}
Judgment:
1import requests
2
3API_URL = "YOUR_HF_ENDPOINT_URL"
4HF_TOKEN = "hf_xxx"
5
6headers = {
7 "Authorization": f"Bearer {HF_TOKEN}",
8 "Content-Type": "application/json"
9}
10
11def judge(context, question, answer):
12 prompt = f"""You are a system that detects hallucinations in RAG answers.
13
14Decide whether the answer is fully supported by the context.
15Reply with only one word: PASS or FAIL.
16
17[CONTEXT]
18{context}
19
20[QUESTION]
21{question}
22
23[ANSWER]
24{answer}
25
26Judgment:"""
27
28 payload = {
29 "inputs": prompt,
30 "parameters": {
31 "max_new_tokens": 5,
32 "do_sample": False,
33 "temperature": 0.0
34 }
35 }
36
37 response = requests.post(API_URL, headers=headers, json=payload)
38 return response.json()[0]["generated_text"]| Field | Description |
|---|---|
| Context | Retrieved passages |
| Question | User query |
| Answer | LLM-generated answer |
| Label | PASS / FAIL |