HaloGuard
A local-first hallucination firewall for LLM applications. HaloGuard sits between an LLM and the application consuming its output, scoring every response for hallucination risk before it reaches a user. Everything runs on the caller's machine -- no prompt, response, or context ever leaves the device.
Scoring modes
- Entailment mode (RAG-style): scores whether the response is supported by supplied
source context, using an NLI cross-encoder (
DeBERTa-v3-small, ONNX, quantized). - Consistency mode (no context): scores whether the response is internally consistent, cross-checking its own claims with the same NLI model.
Mode is selected automatically by input shape (auto), or set explicitly.
Install
pip install haloguard
One-time model setup (builds the ONNX artifact into your local cache):
pip install "haloguard[export]"
python scripts/export_onnx.py
SDK quickstart
from haloguard import Firewall
fw = Firewall() # threshold=0.7, block_threshold=0.9, mode="auto"
# Entailment mode: context supplied
result = fw.check(
prompt="Where is the Eiffel Tower?",
response="The Eiffel Tower is in Paris.",
context="The Eiffel Tower is located in Paris and was completed in 1889.",
)
print(result.verdict, result.score, result.reason)
# Consistency mode: no context
result = fw.check(
prompt="When is the meeting?",
response="The meeting is on Tuesday. The meeting is on Friday.",
)
Every check returns a FirewallResult. Also available: acheck() (async),
check_batch() (many items over one loaded session).
CLI
haloguard check --prompt "..." --response "..." # consistency mode
haloguard check --prompt "..." --response "..." --context FILE # entailment mode
haloguard check ... --json # machine-readable
haloguard version
Exit codes: 0 PASS / 1 FLAG / 4 BLOCK / 3 internal error (incl. UNKNOWN).
Framework hooks
# LangChain: pip install "haloguard[langchain]"
from haloguard.integrations.langchain_handler import HaloGuardCallbackHandler
handler = HaloGuardCallbackHandler(context_provider=lambda _text: retrieved_context)
# LlamaIndex-style query responses (duck-typed, no hard dependency)
from haloguard.integrations.llamaindex_handler import HaloGuardQueryHook
result = HaloGuardQueryHook().check_response(query_response)
# Any client SDK: adapt to generate(prompt) -> str, then score
from haloguard.integrations.raw_wrappers import guarded_call, openai_generate
response, result = guarded_call(openai_generate(client), prompt, context=context)
Verdicts
score-- 0.0-1.0 hallucination risk (higher = more likely hallucinated)verdict--PASS(risk < threshold),FLAG(threshold <= risk < block_threshold),BLOCK(risk >= block_threshold),UNKNOWN(scoring failed, fail-open)reason,mode_used,latency_ms
UNKNOWN is the fail-open verdict returned when scoring itself fails and
strict_mode=False (the default). Set strict_mode=True to fail closed instead.
Honest limitations
HaloGuard is defense-in-depth, not a guarantee. An adversarially crafted response can read as entailed/consistent to any NLI model while still being false. The measured false-negative rate on the golden benchmark is the real accuracy statement; treat HaloGuard as one layer in a safety stack, not the only one.
Development
pip install -e ".[dev]"
pytest tests -v # unit tests always; integration tests need model artifacts
ruff check src tests scripts
mypy
Integration tests run real inference against tests/golden_dataset/labeled_pairs.jsonl
and are skipped automatically when model artifacts are absent.
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 haloguard-0.1.3.tar.gz.
File metadata
- Download URL: haloguard-0.1.3.tar.gz
- Upload date:
- Size: 22.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4ecfab7380f704f3ec997476b9c00ade3435e8bdd3ffbf81766fed3b8582e28
|
|
| MD5 |
886dc65ff3795910f14af641df7017c6
|
|
| BLAKE2b-256 |
294cdb48acc82ac921b90a28449c6f7f3db65a136b0f1d7fb30f3c2d8a42bbb1
|
File details
Details for the file haloguard-0.1.3-py3-none-any.whl.
File metadata
- Download URL: haloguard-0.1.3-py3-none-any.whl
- Upload date:
- Size: 21.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68e38e445cc343ef369ac9ae505d80e81446a94ff322fc1fc441e33d0fdff407
|
|
| MD5 |
c876617f65fc5c2e2a1851de308e9ebf
|
|
| BLAKE2b-256 |
a41f8fcc1cfe6ff635f04e1a27a228946416ed60eaa6fab1744a3f14abc3cf7e
|