You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 95afc6b
Browse filesBrowse the repository at this point in the historyBrowse files
**When to use:** Quick prototyping, or when you want the LLM to explain *why* something is hallucinated.
31
31
32
+
### Backends
33
+
34
+
Beyond OpenAI-compatible APIs, the detector now ships an `LLMClient` abstraction with an AWS Bedrock backend. Select it with `provider`, or pass your own `client` for a custom backend:
The OpenAI backend uses strict JSON-schema structured output; Bedrock obtains the same structured output through a forced tool call.
46
+
47
+
### Reasoning and confidence
48
+
49
+
Set `include_reasoning=True` to make the model reason before it judges. The response opens with a claim-by-claim `analysis` scratchpad, and each span carries a short `reasoning`, a `confidence` score (0–1), and an `is_hallucination` verdict. Spans the model talks itself out of (verdict `false`) are discarded automatically, and the `confidence`/`reasoning` keys are added to the returned spans.
50
+
51
+
```python
52
+
detector = HallucinationDetector(
53
+
method="llm",
54
+
model="gpt-4.1-mini",
55
+
include_reasoning=True,
56
+
min_confidence=0.7, # drop low-confidence spans
57
+
)
58
+
```
59
+
60
+
`min_confidence` filters out spans scored below the threshold (only meaningful together with `include_reasoning`).
61
+
62
+
### Taxonomy classification
63
+
64
+
Set `include_taxonomy=True` to classify each hallucination into one of the unified taxonomy categories, or pass a list of category names to use a custom set. The chosen label is returned under a `category` key on each span.
With `include_taxonomy=True` the unified taxonomy is used, with these categories:
71
+
72
+
| Category | Definition |
73
+
|---|---|
74
+
|`contradiction`| The span directly conflicts with the context: the context states one thing and the answer asserts a different, incompatible thing. |
75
+
|`unsupported_addition`| The span asserts something the context neither states nor implies — plausible, but not derivable from the context. |
76
+
|`fabricated_reference`| The span references a named element (identifier, section, file, entity, attribute) that does not appear anywhere in the context. |
77
+
78
+
Pass a `{category: description}` dict instead of `True` to classify against your own taxonomy. The descriptions are injected into the prompt so the model knows what each label means:
79
+
80
+
```python
81
+
detector = HallucinationDetector(
82
+
method="llm",
83
+
model="gpt-4.1-mini",
84
+
include_taxonomy={
85
+
"unsupported_claim": "a statement not backed by anything in the source",
86
+
"contradiction": "directly contradicts the source",
87
+
"wrong_entity": "right relation but the wrong name, place, or number",
88
+
},
89
+
)
90
+
```
91
+
92
+
You can also pass a plain list of names; definitions are reused from the built-in taxonomy where the name matches and omitted otherwise.
93
+
94
+
### Verification pass
95
+
96
+
Set `verify=True` to run a second, deliberately strict pass that re-judges each flagged span against the source and drops the ones it cannot confirm. Spans the verifier does not return are kept, so a malformed verdict never silently discards confirmed detections.
0 commit comments