Receipts
A hash-chained record of every decision, request, answer and execution, how to verify it, and what verification does and does not prove.
Code blocks on this page are excerpts of tested programs; each block's title names its file in examples/, where the complete program runs.
Turn receipts on with receipts= when you build the gate: a JSONL file path, a receipt store, or true to use the
approval store's own receipts table (SQLite and Postgres have one).
desk = SupportDesk()
gate = hitl.Gate(
POLICY,
channels=[desk],
receipts=RECEIPTS, # hash-chained JSONL audit log
clock=FakeClock("2026-11-25T10:00:00Z"),
)
@gate
async def issue_refund(order_id: str, amount: float) -> str:
"""Refund an order."""
return f"Refunded ${amount:g} on {order_id}"const gate = new Gate(POLICY, {
channels: [supportDesk],
receipts: RECEIPTS, // hash-chained JSONL audit log
clock: new FakeClock("2026-11-25T10:00:00Z"),
});
const issueRefund = gate.tool({
name: "issue_refund",
description: "Refund an order",
input_schema: {
type: "object",
properties: { order_id: { type: "string" }, amount: { type: "number" } },
required: ["order_id", "amount"],
},
execute: async ({ order_id, amount }) => `Refunded $${amount} on ${order_id}`,
});What is recorded
One chain per receipt store. Each entry has a kind:
| Kind | Written when |
|---|---|
decision | An action was evaluated (at authorize, and again at consume with phase: consume) |
approval_requested | An approval was created and delivered |
approval_response | A review arrived (accepted or not) |
approval_decided | The approval reached a terminal status |
executed | The tool ran, with the outcome (ok, or the error type) and its execution_key; hitl.unsettled when sweep() released an execution nobody settled |
operator_action | An operator did something outside the gate ({ action, target, by }), so one chain holds gate decisions and operator actions |
The $20 and $900 refunds of the quickstart produce eight entries: decision, executed for the small one;
decision, approval_requested, approval_response, approval_decided, then decision, executed at consume
for the large one.
People and control planes act outside the gate too. Append those as operator_action entries with a ReceiptLog
over the same store; the example's lead flags the refunded order, the ninth entry:
# Things people do outside the gate go on the same chain: here a lead flags the refunded order for a follow-up.
audit = hitl.ReceiptLog(hitl.FileReceipts(RECEIPTS))
await audit.operator_action(action="order.flagged", target="A-1002", by="desk:omar")// Things people do outside the gate go on the same chain: here a lead flags the refunded order for a follow-up.
const audit = new ReceiptLog(new FileReceipts(RECEIPTS));
await audit.operatorAction({ action: "order.flagged", target: "A-1002", by: "desk:omar" });Entries carry digests, never raw arguments: the action's args_digest and action_digest, the policy digest, the
rules, the effect, the risk, and who decided. Each entry's entry_digest is a SHA-256 over its canonical JSON plus
the previous entry's digest, so changing, removing or reordering an entry without recomputing the rest breaks the
chain (see What verification proves for what it cannot catch).
With tenants, each tenant has its own chain in the store (see Tenants); receipts verify --chain <tenant> verifies one.
Fail closed, then best effort
An entry written before the side effect (a decision, a request) is required by default: if it cannot be
written, the action is denied with hitl.receipt_failed (receipts_required / receiptsRequired turns this off).
The executed entry comes after a side effect that cannot be undone, so it is retried with backoff on the gate's
clock and then reported as hitl.receipt_lost through on_error / onError; the tool result is still returned.
Verify
In code:
result = await hitl.verify_receipts(hitl.FileReceipts(RECEIPTS).read())
print(f"receipts verified: {result.ok}, {result.count} entries") # receipts verified: True, 9 entriesconst result = await verifyReceipts(new FileReceipts(RECEIPTS).read());
console.log(`receipts verified: ${result.ok}, ${result.count} entries`); // receipts verified: true, 9 entriesFrom a shell, for a JSONL file, a SQLite store or a Postgres DSN:
viewport-hitl receipts verify .viewport/receipts.jsonl
npx @viewportai/hitl receipts verify .viewport/receipts.jsonl --anchor sha256:9f2c...Both recompute every digest and check sequence continuity and links. A broken chain exits 1 and names the first bad entry:
BROKEN at seq 5: entry_digest does not match the entry (tampered or corrupted)What verification proves
The digests are plain SHA-256, with no key. Verification catches accidental corruption and edits by someone who does not rewrite the rest of the chain. It does not stop someone with write access to the receipts:
- They can change an entry and recompute every digest after it; the result verifies.
- They can cut the last entries off; a shorter chain verifies.
--anchor sha256:...(oranchor=in code) requires a digest you pinned earlier, kept somewhere they cannot write, to be in the chain. That proves the chain up to the anchor is unchanged, and nothing after it.
So protect the receipts store like any audit log, and pin a recent head digest outside it (receipts verify prints
it) when you need to prove history later. Signed checkpoints, which close these gaps, are planned for v0.2.