Skip to main content

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 / 2 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

haloguard-0.1.1.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

haloguard-0.1.1-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file haloguard-0.1.1.tar.gz.

File metadata

  • Download URL: haloguard-0.1.1.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.10

File hashes

Hashes for haloguard-0.1.1.tar.gz
Algorithm Hash digest
SHA256 52837ada4386d348aa436ebd4a1db43bf8adfac8248db76a15ef5b705d4616db
MD5 b3add578d223944f97fe99008127d716
BLAKE2b-256 4e72946a0f9c0da332316aef2d93486cacfb1555fbadd488cec58eab2e3d83a1

See more details on using hashes here.

File details

Details for the file haloguard-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: haloguard-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.10

File hashes

Hashes for haloguard-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 40134f5a596a84dada69a7c3e1009786b7e8f9d62a54023244b828f04d64d703
MD5 44b1053c65e7c3f20c40767348336ddf
BLAKE2b-256 020c1a5153559887792624aea8afea444b490b28c62b981c654d6152ea2b6518

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

This release

0.1.1 This release

2 files

0.1.0

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page