Skip to main content

PyPI version Python

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

The model downloads automatically on first use (~160 MB, cached locally). No manual setup required.

If you want to rebuild the ONNX artifact from source instead:

pip install "haloguard[export]" python -c "import runpy; runpy.run_module('haloguard.scripts.export_onnx')"

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

haloguard-0.1.5.tar.gz (23.0 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.5-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: haloguard-0.1.5.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for haloguard-0.1.5.tar.gz
Algorithm Hash digest
SHA256 bf178908492657012e1c6d98df6d92d782f2b04e255191407c631d5d89f0db7e
MD5 17e1e17d14822e3bee780ed14791bf91
BLAKE2b-256 ebe92cca0a08ab5d2a92cb293f94c3da46bb0996e2c348da5586b1267378d6bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for haloguard-0.1.5.tar.gz:

Publisher: publish.yml on KunalSoyane/Halogaurd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: haloguard-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for haloguard-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e2acd01182af32842afdff2a64f1a692bcd900b0455bc79f93e2c4846ef6716d
MD5 9f2634b7ba39e9344105553f45f28285
BLAKE2b-256 8d2395e6e67c8eedc5feabd48f25a29ae560002d352f52938827985f652bec53

See more details on using hashes here.

Provenance

The following attestation bundles were made for haloguard-0.1.5-py3-none-any.whl:

Publisher: publish.yml on KunalSoyane/Halogaurd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

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