Trust-weighted hallucination detection for AI agents. Verify LLM outputs against multiple sources with contradiction awareness. Zero dependencies. Sub-2ms.
Project description
GroundCheck
Trust-weighted hallucination detection for AI agents. Zero dependencies. Sub-2ms.
The Problem
Your AI agent says "you work at Amazon." Memory says "Microsoft." Most systems won't catch this — they just return the most similar embedding and hope for the best. GroundCheck catches it in <2ms with zero dependencies.
Install
pip install groundcheck
10-Second Demo
from groundcheck import GroundCheck, Memory
verifier = GroundCheck()
memories = [
Memory(id="m1", text="User works at Microsoft", trust=0.9),
Memory(id="m2", text="User lives in Seattle", trust=0.8),
]
result = verifier.verify("You work at Amazon and live in Seattle", memories)
print(result.passed) # False
print(result.hallucinations) # ["Amazon"]
print(result.corrected) # "You work at Microsoft and live in Seattle"
print(result.confidence) # 0.65
What Makes This Different
Other systems treat verification as a binary "is this grounded?" check against a single source. GroundCheck is different:
| Other systems | GroundCheck | |
|---|---|---|
| Sources | Single string or premise/hypothesis pair | Multiple memories with per-source trust scores |
| Trust | All sources treated equally | Trust-weighted — high-trust memories override low-trust |
| Contradictions | Not detected | Cross-memory conflict detection with resolution |
| Correction | Flag only — no fix | Auto-rewrites hallucinations with grounded facts |
| Temporal | No awareness | most_recent vs most_trusted resolution |
| Dependencies | Often torch, transformers, etc. | Zero (stdlib only) |
| Latency | 500ms – 3,000ms+ | 1.17ms mean |
| Extra LLM calls | Some require 3-5 per check | Zero |
How It Works
Generated text + Retrieved memories (with trust scores)
→ Extract fact claims (slot-based: name, employer, location, ...)
→ Detect contradictions across memories
→ Build grounding map (fuzzy match claims to memories)
→ Check disclosure requirements (trust-weighted)
→ Calculate confidence score
→ Generate corrections (strict mode)
→ VerificationReport
Trust-Weighted Verification
GroundCheck doesn't treat all sources equally. Each memory has a trust score:
memories = [
Memory(id="m1", text="User is named Alice", trust=0.9), # High trust
Memory(id="m2", text="User is named Bob", trust=0.3), # Low trust
]
result = verifier.verify("Your name is Bob", memories)
print(result.requires_disclosure) # True — trust gap > 0.3
print(result.contradiction_details[0].most_trusted_value) # "alice"
print(result.contradiction_details[0].most_recent_value) # depends on timestamps
Verification Modes
strict— generates corrected text, replaces hallucinations with grounded factspermissive— detects and reports, doesn't rewrite
result = verifier.verify("You live in Paris", memories, mode="strict")
print(result.corrected) # Rewritten with grounded facts
result = verifier.verify("You live in Paris", memories, mode="permissive")
print(result.corrected) # None — permissive doesn't rewrite
Supported Fact Slots
15+ built-in slot types with mutual exclusivity knowledge:
name, employer, location, title, occupation, age, school,
degree, favorite_color, coffee, hobby, pet, project,
graduation_year, programming_experience, and more.
GroundCheck knows that a person can only have one employer at a time, but can have multiple hobbies. This built-in domain knowledge prevents false positives.
Neural Mode (Optional)
For paraphrase handling and semantic matching:
pip install groundcheck[neural]
# Automatically used when sentence-transformers is installed
verifier = GroundCheck() # Detects neural availability
result = verifier.verify("Employed by Google", memories) # Matches "works at Google"
| Mode | Paraphrase Accuracy | Latency |
|---|---|---|
| Regex-only (default) | 70% | 1.17ms |
| Neural | 85-90% | ~15ms |
API Reference
GroundCheck
verify(generated_text, retrieved_memories, mode="strict")→VerificationReportextract_claims(text)→Dict[str, ExtractedFact]find_support(claim, memories)→ match info
VerificationReport
passed: bool— did verification pass?corrected: Optional[str]— rewritten text (strict mode)hallucinations: List[str]— hallucinated valuesgrounding_map: Dict— claim → supporting memoryconfidence: float— trust-weighted confidence (0.0-1.0)contradiction_details: List[ContradictionDetail]— full conflict inforequires_disclosure: bool— must the response acknowledge conflicts?
Memory
id: str— unique identifiertext: str— memory contenttrust: float— trust score (0.0-1.0, default 1.0)timestamp: Optional[int]— when this was stored
ContradictionDetail
slot: str— which fact slot conflictsvalues: List[str]— conflicting valuesmost_trusted_value— value from highest-trust memorymost_recent_value— value from most recent memory
Performance
Benchmark: 1,000 verifications
Mean latency: 1.17ms
P95 latency: 2.09ms
P99 latency: 3.41ms
Memory: ~2MB RSS
Dependencies: 0
MCP Server (Agent Integration)
GroundCheck ships with an MCP server that gives any AI agent persistent fact memory with contradiction detection. Works with VS Code Copilot, Claude Desktop, Cursor, and any MCP-compatible client.
pip install groundcheck[mcp]
Add to your config (VS Code .vscode/mcp.json, Claude claude_desktop_config.json, etc.):
{
"servers": {
"groundcheck": {
"command": "groundcheck-mcp",
"args": ["--db", ".groundcheck/memory.db"]
}
}
}
Three tools are exposed:
| Tool | When to call | What it does |
|---|---|---|
crt_store_fact |
User states a fact | Stores with trust score, detects contradictions |
crt_check_memory |
Before answering about the user | Returns relevant memories with trust scores |
crt_verify_output |
Before sending a response | Catches hallucinations, auto-corrects, scores confidence |
Development
git clone https://github.com/blockhead22/GroundCheck.git
cd GroundCheck
python -m venv .venv
.venv\Scripts\activate # or source .venv/bin/activate
pip install -e ".[dev]"
pytest
License
MIT
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
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 groundcheck-0.2.0.tar.gz.
File metadata
- Download URL: groundcheck-0.2.0.tar.gz
- Upload date:
- Size: 65.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4644e6aa3b4ee6086e5985895210b992a5d2ace157b94f660ba2dd0356b75ed
|
|
| MD5 |
287b53347e9aeb9a0b153bdac717af92
|
|
| BLAKE2b-256 |
d814da64f9ef0d38714d617e4d73ef78a793665f7cd2e8edfc2b797b3c1ad1d3
|
Provenance
The following attestation bundles were made for groundcheck-0.2.0.tar.gz:
Publisher:
workflow.yml on blockhead22/GroundCheck
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
groundcheck-0.2.0.tar.gz -
Subject digest:
e4644e6aa3b4ee6086e5985895210b992a5d2ace157b94f660ba2dd0356b75ed - Sigstore transparency entry: 936650518
- Sigstore integration time:
-
Permalink:
blockhead22/GroundCheck@4bf556025a2f9def8cdcfd643880f4060eac8c20 -
Branch / Tag:
refs/tags/groundcheck-v0.2.0 - Owner: https://github.com/blockhead22
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@4bf556025a2f9def8cdcfd643880f4060eac8c20 -
Trigger Event:
push
-
Statement type:
File details
Details for the file groundcheck-0.2.0-py3-none-any.whl.
File metadata
- Download URL: groundcheck-0.2.0-py3-none-any.whl
- Upload date:
- Size: 47.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 |
17c79b5736f2bafcf023fa33e311b89600f45c8e5ba784494896743e10533d40
|
|
| MD5 |
73910eff02a130684b4b3b5bf4991f05
|
|
| BLAKE2b-256 |
40aedeb64fa77345910e35188aee19e9790a1cb0ff7e3db4192efdf02ea69ace
|
Provenance
The following attestation bundles were made for groundcheck-0.2.0-py3-none-any.whl:
Publisher:
workflow.yml on blockhead22/GroundCheck
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
groundcheck-0.2.0-py3-none-any.whl -
Subject digest:
17c79b5736f2bafcf023fa33e311b89600f45c8e5ba784494896743e10533d40 - Sigstore transparency entry: 936650519
- Sigstore integration time:
-
Permalink:
blockhead22/GroundCheck@4bf556025a2f9def8cdcfd643880f4060eac8c20 -
Branch / Tag:
refs/tags/groundcheck-v0.2.0 - Owner: https://github.com/blockhead22
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@4bf556025a2f9def8cdcfd643880f4060eac8c20 -
Trigger Event:
push
-
Statement type: