29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/ruby_llm/tribunal/judges/hallucination.rb', line 29
def prompt(test_case, _opts)
context = format_context(test_case.context)
<<~PROMPT
You are evaluating whether an LLM output contains hallucinations.
A hallucination is a factual claim that cannot be verified from the provided context.
## Context
#{context}
## Question
#{test_case.input}
## Output to Evaluate
#{test_case.actual_output}
## Evaluation Process
1. Extract each factual claim from the output (skip opinions, hedged statements)
2. For each claim, check if it can be inferred from the context
3. Identify any claims that are unsupported or contradict the context
## Hallucination Types
- **Fabrication**: Inventing facts not present in context (e.g., dates, names, numbers)
- **Contradiction**: Stating something that conflicts with the context
- **Extrapolation**: Drawing conclusions the context doesn't support
- **Conflation**: Mixing up entities or attributes from the context
## NOT Hallucinations
- Paraphrasing or summarizing context accurately
- Common knowledge that doesn't conflict with context
- Hedged language ("might be", "possibly", "it seems")
- Logical inferences clearly supported by context
## Response Format
Respond with JSON:
- verdict: "yes" if any hallucination detected, "no" if all claims are supported
- reason: List each hallucinated claim and explain why it's unsupported
- score: 0.0 (no hallucination) to 1.0 (severe/multiple hallucinations)
PROMPT
end
|