Real-time LLM hallucination guardrail — NLI + RAG fact-checking with token-level streaming halt
Project description
Director-AI
Real-time LLM hallucination guardrail — NLI + RAG fact-checking with token-level streaming halt
What It Does
Director-AI sits between your LLM and the user. It scores every output for hallucination before it reaches anyone — and can halt generation mid-stream if coherence drops below threshold.
graph LR
LLM["LLM<br/>(any provider)"] --> D["Director-AI"]
D --> S["Scorer<br/>NLI + RAG"]
D --> K["StreamingKernel<br/>token-level halt"]
S --> V{Approved?}
K --> V
V -->|Yes| U["User"]
V -->|No| H["HALT + evidence"]
Three things make it different:
- Token-level streaming halt — not post-hoc review. Severs output the moment coherence degrades.
- Dual-entropy scoring — NLI contradiction detection (DeBERTa) + RAG fact-checking against your knowledge base.
- Your data, your rules — ingest your own documents. The scorer checks against your ground truth.
Quickstart
| Method | Command |
|---|---|
| pip install | pip install director-ai |
| CLI scaffold | director-ai quickstart --profile medical |
| Colab | |
| HF Spaces | Try it live |
| Docker | docker run -p 8080:8080 ghcr.io/anulum/director-ai:latest |
6-line guard
from director_ai import guard
from openai import OpenAI
client = guard(
OpenAI(),
facts={"refund_policy": "Refunds within 30 days only"},
threshold=0.6,
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "What is the refund policy?"}],
)
Score a response
from director_ai.core import CoherenceScorer, GroundTruthStore
store = GroundTruthStore()
store.add("sky color", "The sky is blue due to Rayleigh scattering.")
scorer = CoherenceScorer(threshold=0.6, ground_truth_store=store)
approved, score = scorer.review("What color is the sky?", "The sky is green.")
print(approved) # False
print(score.score) # 0.42
Streaming halt
from director_ai.core import StreamingKernel
kernel = StreamingKernel(hard_limit=0.4, window_size=5)
session = kernel.stream_tokens(token_generator, lambda tok: my_scorer(tok))
if session.halted:
print(f"Halted at token {session.halt_index}: {session.halt_reason}")
Installation
pip install director-ai # heuristic scoring
pip install director-ai[nli] # NLI model (DeBERTa)
pip install director-ai[vector] # ChromaDB knowledge base
pip install "director-ai[nli,vector,server]" # production stack
Framework integrations: [langchain], [llamaindex], [langgraph], [haystack], [crewai].
Full installation guide: docs.
Docker
docker run -p 8080:8080 ghcr.io/anulum/director-ai:latest # CPU
docker run --gpus all -p 8080:8080 ghcr.io/anulum/director-ai:gpu # GPU
Benchmarks
Accuracy — LLM-AggreFact (29,320 samples)
| Model | Balanced Acc | Params | Latency | Streaming |
|---|---|---|---|---|
| Bespoke-MiniCheck-7B | 77.4% | 7B | ~100 ms | No |
| Director-AI (FactCG) | 75.8% | 0.4B | 14.6 ms | Yes |
| MiniCheck-Flan-T5-L | 75.0% | 0.8B | ~120 ms | No |
| MiniCheck-DeBERTa-L | 72.6% | 0.4B | ~120 ms | No |
75.8% balanced accuracy at 17x fewer params than the leader. 14.6 ms/pair with ONNX GPU batching — faster than every competitor at this accuracy tier. Director-AI's unique value is the system: NLI + KB + streaming halt.
Full results: benchmarks/comparison/COMPETITOR_COMPARISON.md.
Domain Presets
8 built-in profiles with tuned thresholds:
director-ai config --profile medical # threshold=0.75, NLI on, reranker on
director-ai config --profile finance # threshold=0.70, w_fact=0.6
director-ai config --profile legal # threshold=0.68, w_logic=0.6
director-ai config --profile creative # threshold=0.40, permissive
Known Limitations
- Heuristic fallback is weak: Without
[nli], scoring uses word-overlap heuristics (~55% accuracy). Usestrict_mode=Trueto return neutral 0.5 instead. - Summarisation is a weak spot: NLI models under-perform on summarisation (AggreFact-CNN: 68.8%, ExpertQA: 59.1%).
- ONNX CPU is slow: 383 ms/pair without GPU. Use
onnxruntime-gpufor production. - Weights are domain-dependent: Default
w_logic=0.6, w_fact=0.4suits general QA. Adjust for your domain. - Chunked NLI: Very short chunks (<3 sentences) may lose context.
Citation
@software{sotek2026director,
author = {Sotek, Miroslav},
title = {Director-AI: Real-time LLM Hallucination Guardrail},
year = {2026},
url = {https://github.com/anulum/director-ai},
version = {2.0.0},
license = {AGPL-3.0-or-later}
}
License
Dual-licensed:
- Open-Source: GNU AGPL v3.0 — research, personal use, open-source projects.
- Commercial: Proprietary license — removes copyleft for closed-source and SaaS.
See Licensing for pricing tiers and FAQ.
Contact: anulum.li/contact | invest@anulum.li
Contributing
See CONTRIBUTING.md. By contributing, you agree to AGPL v3 terms.
Project details
Release history Release notifications | RSS feed
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 director_ai-2.0.0.tar.gz.
File metadata
- Download URL: director_ai-2.0.0.tar.gz
- Upload date:
- Size: 148.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9dba30dc9fc257e8c1d7c751f1fe7a5e66b52676d58cda67672b2e58fdd09bac
|
|
| MD5 |
3837061d302ccacf299ee2b19a342a97
|
|
| BLAKE2b-256 |
625677a8d2e7ef82b743dc7b50cd1b95e977c1a8fbf2f3e5210c72f5e3d0f2a3
|
Provenance
The following attestation bundles were made for director_ai-2.0.0.tar.gz:
Publisher:
publish.yml on anulum/director-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
director_ai-2.0.0.tar.gz -
Subject digest:
9dba30dc9fc257e8c1d7c751f1fe7a5e66b52676d58cda67672b2e58fdd09bac - Sigstore transparency entry: 1008569504
- Sigstore integration time:
-
Permalink:
anulum/director-ai@739e843b561f235c693cae9c79d926f2049956cc -
Branch / Tag:
refs/tags/v2.0.0 - Owner: https://github.com/anulum
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@739e843b561f235c693cae9c79d926f2049956cc -
Trigger Event:
release
-
Statement type:
File details
Details for the file director_ai-2.0.0-py3-none-any.whl.
File metadata
- Download URL: director_ai-2.0.0-py3-none-any.whl
- Upload date:
- Size: 95.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f54b709d3ab93b2e99156be75259732642466ea47bf2e6679d5926276c19c09f
|
|
| MD5 |
aafc90c3b22e3a59f73217610f1aea50
|
|
| BLAKE2b-256 |
71c370f55349af272f1f9ceb8dfea1cd65362a564f79a11ab2d626d5ac11bf1b
|
Provenance
The following attestation bundles were made for director_ai-2.0.0-py3-none-any.whl:
Publisher:
publish.yml on anulum/director-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
director_ai-2.0.0-py3-none-any.whl -
Subject digest:
f54b709d3ab93b2e99156be75259732642466ea47bf2e6679d5926276c19c09f - Sigstore transparency entry: 1008569513
- Sigstore integration time:
-
Permalink:
anulum/director-ai@739e843b561f235c693cae9c79d926f2049956cc -
Branch / Tag:
refs/tags/v2.0.0 - Owner: https://github.com/anulum
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@739e843b561f235c693cae9c79d926f2049956cc -
Trigger Event:
release
-
Statement type: