groundanchor
Deterministic factual grounding and hallucination verification engine for AI agents and RAG pipelines.
Engineered for production teams needing fast, sub-millisecond, zero-API-cost verification of LLM responses against source documents without relying on slow or non-deterministic LLM-as-a-judge calls.
Key Capabilities
- Zero-API-Cost & Ultra-Low Latency: Pure deterministic Python engine running in sub-50 milliseconds on CPU.
- Numerical & Entity Anchor Verification: Detects subtle numerical contradictions (e.g. source says
14%, LLM generates 18%), currency discrepancies, and unauthorized entity insertions.
- Polarity & Negation Check: Catches negation inversions (e.g. source states "service is not supported", LLM generates "service is supported").
- Attribution Index: Computes composite lexical overlap, longest common subsequence, and Okapi BM25 citation scores.
- Automatic Sanitization: Strips ungrounded claims on the fly, outputting only verified statements.
- Drop-in Guardrail Decorator:
@groundanchor.guard decorates sync and async LLM functions with raise, sanitize, or warn policies.
Installation
pip install groundanchor
Quickstart
import groundanchor
sources = [
"EdgeMind is an open-source Python SDK engineered for local AI image generation. "
"It supports 1-step Hyper-SD acceleration and runs natively on Windows, Linux, and macOS."
]
response = (
"EdgeMind is a Python SDK for local AI image generation supporting 1-step acceleration. "
"It was acquired by an offshore entity for $500M."
)
report = groundanchor.verify(sources=sources, response=response)
print(f"Is Grounded: {report.is_grounded}") # False
print(f"Grounding Score: {report.grounding_score}") # 0.48
print(f"Risk Level: {report.risk_level.value}") # ungrounded
# Sanitize to keep only verified claims:
print(report.sanitized_response())
# Output: "EdgeMind is a Python SDK for local AI image generation supporting 1-step acceleration."
Production Guardrail Decorator
from groundanchor import guard, GroundingViolationError
@guard(threshold=0.80, action="sanitize")
def answer_rag(sources: list[str], question: str) -> str:
# Any LLM call here (OpenAI, Anthropic, Ollama, local models)
return llm.generate(sources, question)
CLI Usage
Audit responses directly in CI/CD or shell pipelines:
groundanchor verify --context docs.txt --response output.txt --threshold 0.75
groundanchor sanitize --context docs.txt --response output.txt
groundanchor redline --context docs.txt --response output.txt
License
MIT License.