Train and evaluate LLMs to avoid hallucinations - 5-line API for RL training with 1M+ examples across 38 datasets
Project description
openenv-halluguard
Train and evaluate LLMs to avoid hallucinations.
pip install openenv-halluguard
Quick Start (5 lines)
from hallucination_guard_env import HallucinationEnv
env = HallucinationEnv()
obs = env.reset()
result = env.step(answer="your answer", confidence=0.8)
print(f"Reward: {result.reward}, Hallucinated: {result.is_hallucination}")
What It Does
HallucinationGuard-Env is an OpenEnv RL environment that trains AI models to:
- Answer only from verified context — no fabrication
- Cite real sources — quote verification
- Calibrate confidence — don't be overconfident when wrong
Evaluation Example
from hallucination_guard_env import HallucinationEnv
def my_model(question, context):
# Call your LLM API here
# Return answer based ONLY on context
return "answer from context"
env = HallucinationEnv()
obs = env.reset()
action = my_model(obs.question, obs.context)
result = env.step(answer=action, confidence=0.8)
print(f"Hallucinated: {result.is_hallucination}")
print(f"Reward: {result.reward}")
HTTP API (HuggingFace Space)
For full deployment, use the HuggingFace Space:
import requests
BASE = "https://samsankar-hallucination-guard-env.hf.space"
# Start episode
obs = requests.post(f"{BASE}/reset").json()
# Submit answer
result = requests.post(f"{BASE}/step",
json={"answer": "your answer"}).json()
# View leaderboard
lb = requests.get(f"{BASE}/leaderboard").json()
Features
- 38 datasets — SQuAD, HaluEval, TruthfulQA, HotpotQA, MedQA, and more
- Research-grade grader — ROUGE + BERTScore + NLI-DeBERTa
- 3 task difficulties — Beginner → Intermediate → Advanced
- 8 hallucination types — Fabricated facts, false citations, overconfident wrong, etc.
Links
- HuggingFace Space: https://huggingface.co/spaces/SamSankar/hallucination-guard-env
- Interactive Docs: https://samsankar-hallucination-guard-env.hf.space/docs
- Leaderboard: https://samsankar-hallucination-guard-env.hf.space/leaderboard
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
openenv_halluguard-2.0.1.tar.gz
(111.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openenv_halluguard-2.0.1.tar.gz.
File metadata
- Download URL: openenv_halluguard-2.0.1.tar.gz
- Upload date:
- Size: 111.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5d54901e167e6e0b9fd647424dd394ef97369949edba8be3a170e1d73511b01
|
|
| MD5 |
143af4c4e5f2bd03930b04f7cfbf76b1
|
|
| BLAKE2b-256 |
0bec42eb5e6df57ac32521a17f40ccf23554e5a83262ed00605344169f5eeb53
|
File details
Details for the file openenv_halluguard-2.0.1-py3-none-any.whl.
File metadata
- Download URL: openenv_halluguard-2.0.1-py3-none-any.whl
- Upload date:
- Size: 44.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e97f74e291a5bd8766680871a785b8e4de5c4d4d370c92d175002e6faeeabda8
|
|
| MD5 |
7fe4af07f9940a95b24d15ab01177a6c
|
|
| BLAKE2b-256 |
644982140f92593da384bec432d1f1a80c77054fdb524dd77dcaa4a0fd376b9f
|