Prove what your AI agent did, and who approved it.
A signed, tamper-evident log of every tool call. Two lines to add. One dependency.
See it catch tampering
git clone https://github.com/ignotia22/hakiki && cd hakiki
pip install -e .
python examples/tamper_demo.py
The demo records four invoice payments, takes a checkpoint after the third, then attacks the log. This is the output of one run. The key fingerprint is different every time:
== 1. The untouched log
INTACT (exit code 0): Every entry carries a valid signature from key 5d61f763c864d652 and the chain is unbroken. Anyone without that key could not have edited, added, removed or reordered entries. The log matches 1 checkpoint.
== 2. One entry edited (approver changed to 'nobody')
TAMPERED (exit code 1): This log does not verify. At least one entry or checkpoint was edited, added, removed, reordered, rewritten after a checkpoint or signed with a different key, so the log cannot be relied on.
- entry 1: contents do not match its hash (edited)
== 3. Last entries deleted, checked WITHOUT checkpoints
INTACT: Every entry carries a valid signature from key 5d61f763c864d652 and the chain is unbroken. Anyone without that key could not have edited, added, removed or reordered entries. No checkpoints were checked, so entries deleted from the end would not be detected.
(missed: this is why checkpoints exist)
== 4. Same truncated log, checked WITH the checkpoint
INCOMPLETE (exit code 2): Entries are missing. An earlier checkpoint recorded more than this log now holds. The entries that are present carry valid signatures from key 5d61f763c864d652 and the chain is unbroken.
- checkpoint 1 shows the log reached 6 entries, but only 4 remain
Case 3 is a miss. Deleting entries from the end leaves a valid chain, so a hash chain on its own cannot see it. Case 4 closes the gap: a checkpoint kept where the operator cannot edit it remembers how long the log was. If someone cuts the log back and writes different entries in their place, the checkpoint no longer matches and the verdict is TAMPERED.
Why Hakiki
| Ordinary application logs | Hakiki | |
|---|---|---|
| Edits detectable | No | Yes. Every entry is hashed, chained to the one before and signed. |
| Deleted entries detectable | No | Yes, with checkpoints stored out of the operator's reach |
| Who approved each action | Only if you build it | Recorded in the same signed log, before the tool runs |
| Stores raw data by default | Usually | No. SHA-256 hashes and a short summary |
| Report a non-engineer can read | No | hakiki report, as HTML or Markdown |
| Extra services to run | None for a local file | None. A Python library and a file |
| Checked independently by a third party | No | Yes, with your public key and hakiki verify |
For business owners. hakiki report turns a log into one HTML page you can hand to a client, insurer or auditor. It opens with a single verdict and a sentence explaining it. Below that it lists what the agent did, who approved each action and whether the approved action was carried out, and it ends with what the report does not prove.
For agent builders. Create a Ledger and decorate your tools. There is no daemon, proxy or server to run. CI tests every push on Python 3.10 to 3.13 on Linux, macOS and Windows.
For engineers. The package is small enough to read in an evening (wc -l src/hakiki/*.py) and depends only on cryptography. It uses SHA-256, Ed25519 and canonical JSON. The test suite attacks the log with edits, deletions, reordering, insertions, forged signatures, wrong keys, truncation, rewritten history and tampered checkpoints, and a fuzz test applies 600 random mutations to a valid log. One test documents the attack it misses without a checkpoint.
Quickstart
pip install hakiki
hakiki keygen # writes hakiki.key (private) and hakiki.pub (public)
Add a ledger to your agent, and a decorator to each tool:
from hakiki import Ledger
ledger = Ledger("run.jsonl", key="hakiki.key", agent="support-bot", model="example-model-1",
checkpoint_every=50, checkpoint_path="checkpoints.jsonl")
@ledger.tool
def lookup_order(order_id):
return {"order_id": order_id, "status": "shipped"}
@ledger.tool(approved_by="jane@example.com")
def send_email(to, body):
...
Anyone with the public key can then check the log and produce a report:
hakiki verify run.jsonl --pubkey hakiki.pub --checkpoints checkpoints.jsonl
hakiki report run.jsonl --pubkey hakiki.pub --checkpoints checkpoints.jsonl --format html --out report.html
verify exits with 0 for intact, 1 for tampered, 2 for incomplete and 3 for a usage error, so it slots into scripts and CI. The examples/ folder has runnable versions of everything in this README.
Works with any model
Hakiki records tool calls, not model internals. The decorator and ledger.call wrap plain Python functions, so they work with any model or framework, or with none. model is a free-text label stored in every entry and shown in the report.
ledger = Ledger("run.jsonl", key="hakiki.key", agent="triage-bot", model="my-local-model")
def lookup_order(order_id): # a plain function, no decorator
return {"order_id": order_id, "status": "shipped"}
ledger.call("lookup_order", lookup_order, {"order_id": "A-1001"})
Two helpers take a model's response, record each tool call in it, run the tool through the ledger and return the messages to send back:
from hakiki.integrations import run_openai_tool_calls, run_anthropic_tool_uses
tool_messages = run_openai_tool_calls(ledger, response, {"lookup_order": lookup_order})
tool_results = run_anthropic_tool_uses(ledger, response, {"lookup_order": lookup_order})
run_openai_tool_calls handles OpenAI Chat Completions and Responses API responses. run_anthropic_tool_uses handles Anthropic Messages responses. Both accept SDK objects or plain dicts, and neither SDK is a dependency. Tool errors and rejected approvals are recorded and returned to the model as error results, so the agent loop keeps going.
A tool with no parameters works too: empty or null arguments, which several providers send, are treated as no arguments.
run_openai_tool_calls also accepts the raw JSON body of a chat-completions response. That is the format servers with an OpenAI-compatible API return, Ollama and vLLM among them. test_openai_compatible_chat_completions_json checks a body in that format. The integration tests use fake responses and make no network calls. They check the format and do not run against any provider's service.
Approvals
Approvals live in the same signed log as the actions they cover. There are three ways to record one:
from hakiki import Approval, ApprovalRejected
@ledger.tool(approved_by="jane@example.com") # standing approval, recorded on every call
def send_receipt(order_id): ...
def refund_policy(tool_name, args): # decided before each call
if args["amount"] <= 100:
return Approval("approved", by="refund-policy", reason="under limit")
return Approval("rejected", by="refund-policy", reason="needs a manager")
@ledger.tool(requires_approval=True, approver=refund_policy)
def issue_refund(order_id, amount): ...
ledger.approve("refund 950 on A-1002", by="manager@example.com") # recorded by hand
With requires_approval=True, the tool runs only when the approver returns Approval("approved", ...). A rejection, no answer, any other return value or an approver that raises all count as no. The decision is logged, the tool does not run, and ApprovalRejected is raised.
In the report, each approval has an Outcome that says only what the log shows: the tool call it led to and whether it succeeded, or that no call was recorded. ledger.approve records a decision made outside the agent, so it is not linked to any tool call, and the report says so rather than implying the action happened.
Privacy
By default the log holds a SHA-256 hash of each set of arguments and each result, plus a summary of type, length and top-level keys. This is the real data field written by lookup_order("A-1001") in the quickstart:
{"args": {"sha256": "0dd3a2b2afaa5ee2f9c3d72769d7935bc51b2a8986f94cb93097cc93dd915303",
"summary": {"keys": ["order_id"], "len": 1, "type": "dict"}},
"tool": "lookup_order"}
A-1001 appears nowhere in the file. A test (test_default_mode_never_stores_raw_values) checks that for arguments, results and error messages. To store raw values, opt in. redact drops the named keys at any depth before anything is hashed or written, in either mode:
Ledger("run.jsonl", key="hakiki.key", capture="full", redact=["password", "api_key"])
redact only removes dictionary keys. It does not search inside values. In capture="full" mode a secret still reaches the file if it is inside a plain string, an exception message, the repr of an object or a list of tuples. If a value might hold a secret, keep the default capture="hash".
Checkpoints
A checkpoint is a small signed record of how far the log had reached: log_id, seq, head_hash, count and ts. If the log later turns out shorter than a checkpoint recorded, verify reports INCOMPLETE. If the entry at that position is a different one, the log was rewritten and verify reports TAMPERED.
hakiki checkpoint run.jsonl --key hakiki.key --out checkpoints.jsonl
The ledger can also write one every N entries: Ledger(..., checkpoint_every=50, checkpoint_path="checkpoints.jsonl").
A checkpoint only protects you if it is stored where the agent's operator cannot edit it. A checkpoint file on the same machine as the log can be trimmed along with it. Copy each one somewhere else as it is made:
- email it to the client
- commit it to a separate repository the operator cannot rewrite
- copy it to separate storage with versioning or write-once retention
Protection reaches the latest checkpoint held somewhere safe. Entries written after it can still be dropped unnoticed.
Reports
hakiki report run.jsonl --pubkey hakiki.pub --checkpoints checkpoints.jsonl --format html --out report.html
hakiki report run.jsonl --pubkey hakiki.pub --format md --out report.md
The HTML report is one file with no JavaScript, and it prints cleanly. Its overview shows when it was generated, the Hakiki version and the SHA-256 of the log and checkpoints files. A report is a summary that anyone could edit, so the way to confirm one is to run hakiki verify on the log yourself and compare the file hash. This is the top of a real report, from running examples/approvals.py and taking one checkpoint:
The full report, including the timeline and the section on what it does and does not prove, is in examples/sample-report.html. Download it and open it in a browser.
How it works
Each event is one line of JSON. This is the entry behind the privacy example above:
{"actor":"ops","agent":"support-bot","data":{"args":{"sha256":"0dd3a2b2...","summary":{"keys":["order_id"],"len":1,"type":"dict"}},"tool":"lookup_order"},"hash":"b93c4838c7b86a8f...","key_id":"4f9d68b887ebdabd","log_id":"08c57a4d-a538-4a61-8e13-641505ce81aa","model":"example-model-1","prev_hash":"0000000000000000...","seq":0,"sig":"89e9b4a8776c0861...","ts":"2026-11-24T19:54:31.483524Z","type":"tool_call","v":1}
- Types.
tool_call,tool_result,tool_error,approval,noteandcheckpoint. Anapprovalfield is added when one applies. - Hash. SHA-256 over the entry's canonical JSON without
hashandsig:json.dumps(entry, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode("utf-8"). - Chain.
prev_hashis the previous entry'shash. The first entry uses 64 zeros. - Signature.
sigis Ed25519 over the hexhash.key_idis a 16-character fingerprint of the public key, for display only. - Verification.
verifychecksseq,prev_hash,hashandsigfor every entry against the public key you pass in. It never trusts a key stored in the log. Checkpoints are signed over their own canonical JSON and checked the same way. - Verdict. TAMPERED if any entry or checkpoint fails, or if a checkpoint's entry exists but is not the one it recorded. Otherwise INCOMPLETE if the log is empty or shorter than a checkpoint recorded. Otherwise INTACT. No file content makes
verifyorreportraise: anything that cannot be checked counts as TAMPERED. - Writes. Appends happen under a lock and are flushed and synced to disk before the call returns. Before each append the ledger checks that the file is the size it left it, and raises
LogChangedErrorif something else has written to it. Reopening a log continues its chain.
The core lives in ledger.py, verify.py, checkpoint.py and entry.py.
Limitations
Hakiki shows that a log was not changed by anyone without the signing key after it was written. It does not show that the log is complete or true.
- No checkpoint, no truncation detection. Without a checkpoint kept out of the operator's reach, entries deleted from the end go unnoticed.
- The key holder can rewrite history. The ledger signs inside the agent's process, so it needs the private key there. Whoever controls that machine can forge new entries, or rewrite the log back to the latest checkpoint they cannot reach. Keep the key out of the agent's working directory, prompts and tools.
- It only sees what it wraps. Actions taken outside
@ledger.tool,ledger.callor the integrations are not recorded. - Timestamps come from the local clock and are not independently certified.
- Hashes are not encryption. A hash of a guessable value, such as "yes", a small amount or an email address from a known list, can be found by trying candidates. Summaries reveal types, lengths and top-level dictionary keys. Redacted keys are dropped before hashing, so the hash does not cover them.
- Approvers are not authenticated. Names, reasons and notes are stored as your code supplies them.
- One writer per log file. Threads sharing one
Ledgerare safe. A secondLedgeron the same file, in the same process or another, getsLogChangedErroron its next write once the first has written. Two writers that append at the very same moment can still each add one entry before both are stopped, and that log then reports TAMPERED. - No async or generator tools yet. Their work has not happened by the time they return, so they cannot be recorded truthfully. Decorating an async function, a generator or an async generator raises
TypeError. A tool that returns an awaitable is recorded as atool_errorand raisesTypeError. A plain function that returns a generator object is not caught: it is logged as finished before the generator runs. redactonly removes dictionary keys. See Privacy above.- Values that are not JSON are captured with
repr(), so their hashes may not be reproducible elsewhere. Theselfandclsarguments of methods are left out for that reason. - Characters UTF-8 cannot encode (lone surrogates, which a bad escape in model output can produce) are stored in Python's
backslashreplaceform, for example the six characters\ud800. Hashes are taken over that form, so they stay reproducible. - A clock that goes backwards is not flagged.
verifydoes not compare timestamps between entries. - Reopening a log does not verify it.
Ledgerreads only the last line, so it carries on writing after a log that was already tampered with. - A crash mid-write can leave a partial last line.
verifythen reports TAMPERED, and the ledger refuses to append.
When Hakiki isn't the right tool
Hakiki is a tamper-evident record and nothing more. If you need to replay agent runs, diff behaviour between versions, enforce policy through a proxy or browse traces in a dashboard, use a fuller observability or governance platform. Hakiki can run alongside it when you also want a signed record that a third party can check.
Roadmap
Planned for 0.2:
- Async tool support, including generators and async generators
- Approval linking:
ledger.approvereturns an ID that a later tool call can reference, so a sign-off and the action it allowed appear as one row - Non-fatal warnings from
verify, starting with timestamps that go backwards - An opt-in
verify_on_open=True, so a ledger refuses to continue a log that does not verify
Later:
- RFC 3161 trusted timestamps for entries and checkpoints
- Adapters for LangChain, CrewAI and MCP
- EU AI Act and ISO 42001 mapping in reports
- A hosted checkpoint service, so checkpoints sit out of the operator's reach by default
Contributing
See CONTRIBUTING.md for how to run the tests and what changes fit.
Security
Report vulnerabilities privately, as described in SECURITY.md.
Licence
Built by David Gitau · HillFrame
Metadata
Release files for hakiki 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hakiki-0.1.1.tar.gz | 57.4 kB | With provenance | Details for hakiki-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hakiki-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for hakiki-0.1.1-py3-none-any.whl |
Total release size: 92.2 kB
Release files / hakiki-0.1.1.tar.gz
| Download URL | hakiki-0.1.1.tar.gz |
|---|---|
| Size | 57.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f997fbd2597355c6b2dbf36f0d37c15afb747bd476c6baff91781c7d9ae3befd
|
|
BLAKE2b-256 checksum How to use checksums |
fb1892b6fa3b8b3d7815652a467bc3431141d83d8e6e5a03493acded8ee1f5c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.
Transparency logRelease files / hakiki-0.1.1-py3-none-any.whl
| Download URL | hakiki-0.1.1-py3-none-any.whl |
|---|---|
| Size | 34.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
733fbebeb22594e0c2355725465894987548eeaf8e0570d05617e60111a632ca
|
|
BLAKE2b-256 checksum How to use checksums |
453b36b8ad51b65bfb5ae7b697de8ead67964cf2950d8e9ece723b0a324a7f27
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.
Transparency logSecurity for hakiki 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for hakiki-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.