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.2.tar.gz (22.8 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.2-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: haloguard-0.1.2.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

Hashes for haloguard-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8793ef575cbbf78bf73327204b524c55f8e81a8b3d32738de017390847857363
MD5 77acbd83d64000bf3ac4ba568d011964
BLAKE2b-256 91dee0b5fe47794dc116e4d28bb31cbfebad80b68f4bf4924b13f4ad04f961cf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: haloguard-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 21.4 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 35b535c768078642c5bea5beb9dce90f30ff2d3100e9d49e7a6004767fcd69df
MD5 e1f60615af3b0990c46a3bfacd3960af
BLAKE2b-256 5ee3568facfc22bc7d4854030a502b03bdebb121477dea9d124c783851c6dfeb

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

This release

0.1.2 This release

2 files

0.1.1

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