[KongchangAI]
· 2 min read· 1,224 words

epistemic-guard: Intercepting AI Hallucinated Tool Calls in 10ms and Signing Agent Memories

epistemic-guard: Intercepting AI Hallucinated Tool Calls in 10ms and Signing Agent Memories

epistemic-guard uses signed receipts and clause-level comparison to catch Agent ghost tool claims locally.

epistemic-guard is an MIT-licensed open-source Python package targeting a blind spot of existing tool firewalls: Agents claiming "refunded" or "email sent" when the tool failed or was never called. It checks what the Agent claims to have done rather than what it intends to do, generating signed ToolReceipts via @recorder.tool into an RFC 6962-style Merkle log, then using clause-level comparison (~10.9ms p50 on CPU) to locate unexecuted action claims, with streaming support. ProvenanceGate gates memory writes holding only the Ed25519 public key, blocking prompt-injection self-poisoning; corroborate_sources scales source deduplication by harm severity. The project offers a ~227MB local OpenVINO INT8 model pack with zero LLM API calls, and the author has disclosed known failure modes.

AI Agents tell users "refunded" or "email sent" when a tool call failed or was never made at all—these "ghost tool claims" are a blind spot for existing tool firewalls. The open-source project epistemic-guard catches false claims with clause-level supervision and signed receipts at roughly 10ms latency on CPU/NPU, and adds cryptographic gating to Agent memory writes.

Reddit source: epistemic-guard project introduction

Tool firewalls only cover "before the call," not "didn't call but said they did"

Existing pre-execution tool firewalls (such as MCP permission checks and human-in-the-loop prompts) focus on which tools the Agent attempts to call. They cannot catch the opposite bug: the tool returns HTTP 500, or is never called at all, yet the LLM still tells the user "I have refunded order #8821 and sent the receipt."

While building a local desktop Agent testbed (Project Lucca) and a solo RPG engine (RollSolo, where the narrator is not allowed to fabricate inventory out of thin air), the author of epistemic-guard extracted this verification layer into a standalone MIT-licensed Python package. The core idea: instead of checking what the Agent intends to do, check what the Agent claims to have done and compare it against the actual tool execution records.

Three core mechanisms: receipt supervision, memory gating, provenance deduplication

1. Clause-level and streaming tool receipt supervision

Through the @recorder.tool decorator and ReceiptSupervisor, the project generates signed ToolReceipt records for sync/async Python functions (covering MCP, OpenAI tool calling, LangGraph, PydanticAI) and writes them to an RFC 6962-style Merkle log.

Assistant replies are split into clauses (p50 10.9ms on CPU), unexecuted action claims are flagged with exact character offsets ([start_char, end_char]), and a ready-to-send retry prompt is generated. It also supports streaming SSE/per-token checks (sup.stream(...)) and verify_chat_turn(messages).

The project automatically masks fenced code blocks, Markdown blockquotes, attributed quotes/dialogue, and creative/translation user_prompt contexts—achieving 50/50 on the locked LOCKED_COH_50 holdout set.

2. Public-key-only memory write gating

ProvenanceGate works with SQLiteProvenanceStore, and the verifier holds only the Ed25519 public key (<0.3ms). Even if prompt injection hijacks the Agent loop, the runtime does not hold the private key needed to forge USER_EXPLICIT or TOOL_VERIFIED envelopes, while LLM_NARRATION is rejected by construction: natural self-poisoning is 0/100, versus 100/100 for unguarded RAG.

3. Provenance deduplication scaled by harm severity

corroborate_sources uses SimHash plus 11-word verbatim shingle clustering to merge press releases and copy-paste mirrors (30/30 on R-33), and scales the required number of independent eTLD+1 publishers based on the harm level of multi-clause queries (128/130, i.e. 98.5% safe stratification, at 3.2ms p50 on R-21). It also uses INT8 MiniLM plus DeBERTa-v3 NLI to check cross-paragraph disputes (60/64 dispute accuracy, i.e. 93.8%, on real_web_v1).

What it can and cannot do

The author explicitly lists known failure modes with an honest attitude:

  • ProvenanceGate verifies who signed the memory write (USER_EXPLICIT, TOOL_VERIFIED), not whether the authenticated human user entered a false statement.
  • When user_prompt="" and there is no dialogue attribution, unprompted first-person fabrication is indistinguishable from unreceipted action claims unless user_prompt context or [ACTION: verb target] tags are passed in.
  • On noisy single-shot live web scrapes (real_web_v2, N=64), end-to-end burden accuracy is 47/64 (73.4%) and dispute accuracy is 56/64 (87.5%)—implicit cross-article disagreement between studies, without lexical or single-sentence NLI opposition, still accounts for about 26.6% (17/64) of the remaining open-web error cases.

Runs locally, zero LLM API calls

The project offers an optional ~227MB OpenVINO INT8 model pack (SHA-256 pinned) that runs locally on CPU, GPU, or Intel NPU with no LLM API calls. Getting started takes just three commands:

pip install epistemic-guard
epistemic-guard download-models  # optional ~227 MB OpenVINO INT8 pack (SHA-256 pinned)
epistemic-guard demo

Why it's worth paying attention to

Agent reliability is shifting from "can it call tools" to "do its words match its actions." epistemic-guard pushes verifiability down to the runtime: signed receipts lock in the facts of tool execution, clause-level comparison catches false claims, and public-key gating blocks memory poisoning. MIT-licensed, pure local inference, and wrapper support for mainstream Agent frameworks make it suitable as a verification middleware layer for Agent testing and production environments. The author also openly welcomes adversarial test cases—for a security tool like this, being attackable and testable is itself part of credibility.

Background notes

RFC 6962-style Merkle log: RFC 6962 is the technical standard for Certificate Transparency (certificate transparency logs), whose core is an append-only Merkle hash tree—each new entry is bound to all previous entries via a hash chain, and any tampering with historical records causes a root hash mismatch, making it detectable. epistemic-guard borrows this structure to record ToolReceipt, meaning each tool execution credential not only has a signature but also verifiable append order and tamper-evident properties. The verifier does not need to trust the runtime; holding only the log root hash is enough to confirm that a receipt was indeed written at a specific time and has not been modified afterward, which is better suited to auditing and retrospective tracing than plain signed receipts.

Ed25519 and the security implications of "public-key-only verification": Ed25519 is an elliptic-curve-based digital signature algorithm with extremely fast signing and verification and a public key of only 32 bytes. Its key property is that signatures can only be generated by the private key holder, while verification requires only the public key. The design of ProvenanceGate exploits exactly this: the Agent runtime process loads only the public key, so even if an attacker fully controls the Agent loop through prompt injection, they cannot forge a USER_EXPLICIT or TOOL_VERIFIED envelope—because the private key needed to generate those envelopes is simply not in that process. By contrast, the LLM_NARRATION type is rejected outright, equivalent to architecturally stipulating that "model self-narration cannot be a trusted source for memory," rather than relying on prompts to constrain the model's self-discipline.

SimHash, eTLD+1, and NLI: SimHash is a locality-sensitive hash where documents with similar content produce fingerprints with small Hamming distance, making it suitable for quickly identifying press releases and mirror reposts; combined with verbatim shingle clustering it improves precision. eTLD+1 refers to the effective top-level domain plus one label (e.g. news.example.com normalizes to example.com); using it to count "independent publishers" avoids mistakenly counting multiple subdomains of the same site as multiple independent sources. NLI (natural language inference) models are used to determine whether two passages entail, are neutral toward, or contradict each other, thereby discovering substantive cross-paragraph disputes rather than mere lexical repetition. Together, these three make the strategy of "requiring more independent sources based on harm severity" engineering-feasible.

One-line Summary

epistemic-guard uses signed receipts and clause-level comparison to catch Agent ghost tool claims locally.

Paragraph Summary

epistemic-guard is an MIT-licensed open-source Python package targeting a blind spot of existing tool firewalls: Agents claiming "refunded" or "email sent" when the tool failed or was never called. It does not check what the Agent intends to do but what it claims to have done. Via @recorder.tool it generates signed ToolReceipts written to an RFC 6962-style Merkle log, then uses clause-level comparison (p50 ~10.9ms on CPU) to locate unexecuted action claims, with streaming support. ProvenanceGate can gate memory writes holding only the Ed25519 public key, blocking prompt-injection-induced self-poisoning; corroborate_sources scales source deduplication by harm severity. The project offers a ~227MB local OpenVINO INT8 model pack with zero LLM API calls, and the author has also disclosed known failure modes.

#epistemic-guard#AI Agent hallucination#ghost tool claims#tool receipt supervision#Ed25519 memory gating#prompt injection defense#OpenVINO INT8#Merkle log#Agent reliability
Share:

Related articles