A hash-chained audit trail is a sequence of log entries where each entry includes a cryptographic hash of the previous entry. This creates a chain similar to a blockchain: if any entry is modified, deleted, or reordered, the chain breaks and the tampering is immediately detectable.
Each entry (called a receipt) contains:
Receipt 1: data={...}, hash=H1, prev=null
Receipt 2: data={...}, hash=H2, prev=H1
Receipt 3: data={...}, hash=H3, prev=H2
To verify the chain, walk through the receipts in order and confirm that each receipt's prev hash matches the hash of the preceding receipt. If someone modifies Receipt 2, its hash changes, which means Receipt 3's prev no longer matches, and the chain is broken.
AI agents make decisions and take actions autonomously. When something goes wrong, you need to answer: what did the agent do, in what order, and what decisions led to the outcome?
An ordinary log file can answer these questions, but it can also be modified after the fact. A hash-chained audit trail adds a guarantee: the historical record has not been altered since it was written.
This is critical for:
Verification is fast. Walk the chain, recompute each hash, and compare. If every hash matches, the chain is intact. If any hash does not match, you know exactly which entry was tampered with.
const receipts = await getReceipts(sessionId);
let previousHash = null;
for (const receipt of receipts) {
if (receipt.previousHash !== previousHash) {
throw new Error(`Chain broken at receipt ${receipt.id}`);
}
const computed = sha256(serialize(receipt.data));
if (computed !== receipt.hash) {
throw new Error(`Hash mismatch at receipt ${receipt.id}`);
}
previousHash = receipt.hash;
}
Authensor generates a receipt for every policy decision. The receipt includes the tool name, arguments, policy decision, reason, content scan results, timestamp, and hash chain links. Receipts are stored in PostgreSQL when using the control plane, or in memory for standalone SDK usage.
Receipts are append-only. There is no API to update or delete a receipt. Even the database schema enforces this: the receipts table has no UPDATE or DELETE permissions for the application role. This is a design choice, not a limitation. Audit trails must be immutable to be trustworthy.
Explore more guides on AI agent safety, prompt injection, and building secure systems.
View All Guides