Skip to main content

Epistemic auditor for LLM outputs - quantifies uncertainty to detect hallucinations

Project description

AletheionGuard

Epistemic Auditor for Large Language Models

PyPI version License: AGPL-3.0 Python 3.8+ Documentation

AletheionGuard quantifies aleatoric (Q1) and epistemic (Q2) uncertainty in LLM outputs to detect hallucinations and assess response reliability.


๐Ÿš€ Quick Start

Installation

# Minimal installation
pip install aletheion-guard

# With API server
pip install aletheion-guard[api]

# Full installation (all features)
pip install aletheion-guard[all]

Basic Usage

from aletheion_guard import EpistemicAuditor

# Initialize auditor (model weights included)
auditor = EpistemicAuditor()

# Audit any LLM response
prompt = "What is the capital of France?"
response = "The capital of France is Paris."
audit = auditor.audit(prompt, response)

print(f"Q1 (aleatoric):  {audit.q1:.3f}")      # Data ambiguity
print(f"Q2 (epistemic):  {audit.q2:.3f}")      # Model ignorance
print(f"Height:          {audit.height:.3f}")   # Proximity to truth
print(f"Verdict:         {audit.verdict}")      # ACCEPT | MAYBE | REFUSED

Output:

Q1 (aleatoric):  0.023
Q2 (epistemic):  0.012
Height:          0.999
Verdict:         ACCEPT

CLI Usage

# Audit a response
aletheion-guard audit \
  --prompt "What is 2+2?" \
  --response "2+2 equals 4"

# Start API server
aletheion-guard serve --port 8000

# Show package info
aletheion-guard info

โœจ Key Features

1. Uncertainty Quantification

Separates two types of uncertainty:

  • Q1 (Aleatoric): Irreducible data noise/ambiguity
  • Q2 (Epistemic): Model ignorance/hallucination risk

2. Epistemic Softmax (New in v1.1.0)

from aletheion_guard import epistemic_softmax

# Uncertainty-aware probability distributions
logits = model.get_logits("What is quantum computing?")
probs, uncertainty = epistemic_softmax(logits, return_uncertainty=True)

print(f"Q1: {uncertainty['q1']:.3f}, Q2: {uncertainty['q2']:.3f}")

3. Production-Ready API

# pip install aletheion-guard[api]
from fastapi import FastAPI
from aletheion_guard.api import app

# Or use CLI
# aletheion-guard serve --host 0.0.0.0 --port 8000

API Endpoints:

  • POST /v1/audit - Audit single response
  • POST /v1/batch - Batch auditing
  • POST /v1/compare - Compare models
  • GET /health - Health check

4. Pre-trained Models Included

Model weights (~2.3MB) are bundled:

  • Q1 Gate (aleatoric uncertainty)
  • Q2 Gate (epistemic uncertainty)
  • Height Gate (proximity to truth)
  • Base Forces Network (4-force equilibrium)

๐ŸŽฏ Use Cases

Enterprise LLM Safety Gates

audit = auditor.audit(prompt, llm_response)

if audit.verdict == "REFUSED":
    return "I don't have enough confidence to answer this."
elif audit.q2 > 0.5:
    return "This answer may be unreliable. Please verify."
else:
    return llm_response

RAG Enhancement

audit = auditor.audit(query, rag_response)

if audit.q2 > 0.3:
    # High epistemic uncertainty - retrieve more context
    additional_docs = retriever.get_more_context(query)
    improved_response = llm.generate(query, additional_docs)

Model Comparison

from aletheion_guard import EpistemicAuditor

auditor = EpistemicAuditor()

# Compare calibration across models
models = {
    "gpt-4": gpt4_response,
    "claude-3": claude_response,
    "llama-3": llama_response
}

for model_name, response in models.items():
    audit = auditor.audit(prompt, response)
    print(f"{model_name}: Q2={audit.q2:.3f}, ECE={audit.ece:.3f}")

๐Ÿ—๏ธ Architecture

AletheionGuard implements a pyramidal architecture for epistemic equilibrium:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚      Epistemic Softmax Layer        โ”‚  โ† Uncertainty-aware predictions
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚     Q1 Gate  โ”‚  Q2 Gate  โ”‚ Height   โ”‚  โ† Uncertainty quantification
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚      Base Forces Network            โ”‚  โ† Memory, Pain, Choice, Exploration
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚      Input Processor                โ”‚  โ† Text embeddings
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Inspired by: aletheion-llm Based on: "How to Solve Skynet" research paper


๐Ÿ“ฆ Installation Options

# Core package (minimal dependencies)
pip install aletheion-guard

# With API server
pip install aletheion-guard[api]

# With monitoring (Prometheus, OpenTelemetry)
pip install aletheion-guard[monitoring]

# With ML utilities (PyTorch Lightning, Optuna)
pip install aletheion-guard[ml]

# With visualization (Matplotlib, Seaborn)
pip install aletheion-guard[viz]

# Development tools
pip install aletheion-guard[dev]

# All features
pip install aletheion-guard[all]

๐Ÿ”ฌ Advanced Usage

Custom Model Weights

auditor = EpistemicAuditor(
    model_dir="/path/to/custom/weights"
)

Batch Processing

from aletheion_guard import EpistemicAuditor

auditor = EpistemicAuditor()

prompts = ["Question 1?", "Question 2?", "Question 3?"]
responses = ["Answer 1", "Answer 2", "Answer 3"]

for prompt, response in zip(prompts, responses):
    audit = auditor.audit(prompt, response)
    print(f"Q2: {audit.q2:.3f}, Verdict: {audit.verdict}")

API Server with Docker

FROM python:3.11-slim

RUN pip install aletheion-guard[api]

EXPOSE 8000
CMD ["aletheion-guard", "serve", "--host", "0.0.0.0", "--port", "8000"]

๐Ÿ“Š What Gets Measured

Each audit returns:

Metric Range Description
Q1 [0, 1] Aleatoric uncertainty (data ambiguity)
Q2 [0, 1] Epistemic uncertainty (model ignorance)
Height [0, 1] Proximity to truth: h = 1 - โˆš(Q1ยฒ + Q2ยฒ)
ECE [0, 1] Expected Calibration Error
Verdict enum ACCEPT | MAYBE | REFUSED

๐Ÿ› ๏ธ Development

# Clone repository
git clone https://github.com/AletheionAGI/AletheionGuard.git
cd AletheionGuard

# Install for development
pip install -e ".[dev]"

# Run tests
pytest tests/

# Format code
black src/
isort src/

# Type checking
mypy src/

๐Ÿ“š Documentation


๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide.


๐Ÿ“„ License

Dual Licensed:

  • AGPL-3.0-or-later for open source use
  • Commercial License available for proprietary applications

Contact: research@aletheionagi.com


๐Ÿ”— Links


๐Ÿ† Citation

If you use AletheionGuard in your research, please cite:

@software{aletheionguard2025,
  title = {AletheionGuard: Epistemic Auditor for Large Language Models},
  author = {Aletheion Research Collective},
  year = {2025},
  url = {https://github.com/AletheionAGI/AletheionGuard},
  version = {1.1.0}
}

๐Ÿ“ˆ Project Status

  • โœ… Stable: Core API is stable and production-ready
  • ๐Ÿš€ Active Development: Regular updates and improvements
  • ๐Ÿ“ฆ PyPI: Official package available
  • ๐Ÿค– API: Hosted API available at api.aletheionguard.com

Made with โค๏ธ by Aletheion Research Collective

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aletheion_guard-1.1.0.tar.gz (2.1 MB view details)

Uploaded Source

Built Distribution

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

aletheion_guard-1.1.0-py3-none-any.whl (2.1 MB view details)

Uploaded Python 3

File details

Details for the file aletheion_guard-1.1.0.tar.gz.

File metadata

  • Download URL: aletheion_guard-1.1.0.tar.gz
  • Upload date:
  • Size: 2.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for aletheion_guard-1.1.0.tar.gz
Algorithm Hash digest
SHA256 01760b05ba71d0ea46d278c65b78f1cf9adea67af44ce6d01db22052ad3b3ff1
MD5 634bf4a54d29b4455639c34d1f3abed2
BLAKE2b-256 ad14794992a7d4737f2092a36ebdc6ee596c51cb344cde35394a8c788980e22a

See more details on using hashes here.

File details

Details for the file aletheion_guard-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aletheion_guard-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b2194fcd79278aa66b0296d4183835b1730e3a4bcd300b8465d3f468e569da7
MD5 65489d0e9075ae685ef7e82cbdf59d96
BLAKE2b-256 35c089ab4a9653556f7763b981ec9dfb3f025db5c858de422781b726904c0838

See more details on using hashes here.

Supported by

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