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"]
Four 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.
- Continuous batching — server-level request queue coalesces NLI calls (2 GPU kernels per flush, not 2*N per request).
- Your data, your rules — ingest your own documents. The scorer checks against your ground truth.
Scope
Pure Python core — no compiled extensions required. Optional Rust kernel (pip install director-ai[rust]) for SIMD-accelerated scoring. Works on any platform with Python 3.11+.
| Layer | Packages | Install |
|---|---|---|
| Core (zero heavy deps) | CoherenceScorer, StreamingKernel, GroundTruthStore, SafetyKernel |
pip install director-ai |
| NLI models | DeBERTa, FactCG, MiniCheck, ONNX Runtime | pip install director-ai[nli] |
| Vector DBs | ChromaDB, Pinecone, Weaviate, Qdrant | pip install director-ai[vector] |
| LLM judge | OpenAI, Anthropic escalation | pip install director-ai[openai] |
| Observability | OpenTelemetry spans | pip install director-ai[otel] |
| Server | FastAPI + Uvicorn | pip install director-ai[server] |
Four Ways to Add Guardrails
A: Wrap your SDK (6 lines)
Works with OpenAI, Anthropic, Bedrock, Gemini, Cohere, vLLM, Groq, LiteLLM, Ollama.
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?"}],
)
B: One-shot check (4 lines)
Score a single prompt/response pair without an SDK client:
from director_ai import score
cs = score("What is the refund policy?", response_text,
facts={"refund": "Refunds within 30 days only"})
print(f"Coherence: {cs.score:.3f}")
C: Zero code changes (2 lines)
Point any OpenAI-compatible client at the proxy:
pip install director-ai[server]
director-ai proxy --port 8080 --facts kb.txt --threshold 0.6
Then set OPENAI_BASE_URL=http://localhost:8080/v1 in your app. Every response
gets scored; hallucinations are rejected (or flagged with --on-fail warn).
D: FastAPI middleware (3 lines)
Guard your own API endpoints:
from director_ai.integrations.fastapi_guard import DirectorGuard
app.add_middleware(DirectorGuard,
facts={"policy": "Refunds within 30 days only"},
on_fail="reject",
)
Responses on POST endpoints get X-Director-Score and X-Director-Approved
headers. Set paths=["/api/chat"] to limit which endpoints are scored.
Installation
pip install "director-ai[nli]" # recommended — NLI model scoring
pip install "director-ai[nli,vector,server]" # production stack with RAG + REST API
pip install director-ai # heuristic-only (limited accuracy)
Privacy note: The optional LLM judge mode (
llm_judge_enabled=True) sends truncated prompt+response fragments (500 chars) to an external provider (OpenAI or Anthropic). Do not enable in privacy-sensitive deployments without user consent. The default NLI-only mode runs entirely locally with no external calls.
Extras: [vector] (ChromaDB), [finetune] (domain adaptation), [ingestion] (PDF/DOCX parsing), [colbert] (late-interaction retrieval).
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.
Performance trade-offs and E2E pipeline metrics: docs.
Domain Presets
10 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
Domain-specific benchmarks validate each profile against real datasets:
python -m benchmarks.medical_eval # MedNLI + PubMedQA
python -m benchmarks.legal_eval # ContractNLI + CUAD (RAGBench)
python -m benchmarks.finance_eval # FinanceBench + Financial PhraseBank
Known Limitations
- Heuristic fallback is weak: Without
[nli], scoring uses word-overlap heuristics (~55% accuracy). Usestrict_mode=Trueto reject (0.9) instead of guessing. - Summarisation FPR at 2.0%: Reduced from 95% via bidirectional NLI + Layer C claim decomposition. AggreFact-CNN: 68.8%, ExpertQA: 59.1% (structurally expected at 0.4B params).
- 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 or use a built-in profile. - LLM-as-judge sends data externally: When
llm_judge_enabled=True, truncated prompt+response (500 chars) are sent to the configured provider. Do not enable in privacy-sensitive deployments without user consent.
Citation
@software{sotek2026director,
author = {Sotek, Miroslav},
title = {Director-AI: Real-time LLM Hallucination Guardrail},
year = {2026},
url = {https://github.com/anulum/director-ai},
version = {3.9.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
Community
Join the Director-AI Discord for CI notifications, release announcements, and support. The Discord bot also provides /version, /docs, /install, /status, and /quickstart slash commands.
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-3.9.0.tar.gz.
File metadata
- Download URL: director_ai-3.9.0.tar.gz
- Upload date:
- Size: 529.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
720776b018743bf3813d42db5b8483077156173f0dae7e0dc5c3075bb96b4ec8
|
|
| MD5 |
4c39d6b5da46cf0c2a4cf3a03faff46c
|
|
| BLAKE2b-256 |
08a09ae435ec5086ed9939ba0885272a70191f12ebd1ed968b0696187d31b29b
|
Provenance
The following attestation bundles were made for director_ai-3.9.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-3.9.0.tar.gz -
Subject digest:
720776b018743bf3813d42db5b8483077156173f0dae7e0dc5c3075bb96b4ec8 - Sigstore transparency entry: 1122914604
- Sigstore integration time:
-
Permalink:
anulum/director-ai@e42c04f44656e5b1108568c5b6006cdcd33452ad -
Branch / Tag:
refs/heads/main - Owner: https://github.com/anulum
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e42c04f44656e5b1108568c5b6006cdcd33452ad -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file director_ai-3.9.0-py3-none-any.whl.
File metadata
- Download URL: director_ai-3.9.0-py3-none-any.whl
- Upload date:
- Size: 381.8 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 |
58bb1af6e1fb0ebc5050651ab6d4c6470907c31fe3fe48f307eb20be462dd0b0
|
|
| MD5 |
4568efe53e2cc9d70951f3f6bf6b52cc
|
|
| BLAKE2b-256 |
f73330f930c2af9f7e254d5ba54deaedbca33fe71d2c0c55cf3171771666a7c0
|
Provenance
The following attestation bundles were made for director_ai-3.9.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-3.9.0-py3-none-any.whl -
Subject digest:
58bb1af6e1fb0ebc5050651ab6d4c6470907c31fe3fe48f307eb20be462dd0b0 - Sigstore transparency entry: 1122914608
- Sigstore integration time:
-
Permalink:
anulum/director-ai@e42c04f44656e5b1108568c5b6006cdcd33452ad -
Branch / Tag:
refs/heads/main - Owner: https://github.com/anulum
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e42c04f44656e5b1108568c5b6006cdcd33452ad -
Trigger Event:
workflow_dispatch
-
Statement type: