guard/ is a Python package whose @guard.gated(capability, risk) decorator checks every call to a tool function against a deny-by-default policy, lets you stop calls that are already running, and records a receipt with SHA-256 fingerprints of the arguments and result instead of the values. The console is a browser demo of the same pattern that replays one invented incident drill so you can press Stop mid-run and read the receipt. It is for Python developers who hand functions to an agent as tools.
StatusVerified, package installs from source, console demo on Vercel
RuntimePython 3.11+ standard library, TypeScript port, FastAPI and SQLite for the local console
Proof hooks5 guarantees with Hypothesis and fast-check property tests, shared golden hashes, 102 tests in CI
How it works
Guard.gated in guard.py binds the call’s arguments to the function signature, defaults included, and passes them to Policy.evaluate in policy.py. A call passes when the stop is open, its capability is granted, its declared risk is at or below the grant (read < write < destructive), its budget has calls left and every Rule that applies returns True. A rule that raises counts as a failure. The decision and the budget count happen under one lock, so concurrent calls can’t overspend. A refused call raises Denied or BudgetExhausted before the function body runs.
An admitted call takes a token, the stop generation at admission. StopController moves the generation on at the first latch and at every reset, so a call admitted before a stop can’t complete even if someone resets while it runs. Sync tools end at their next checkpoint(). Async tools are also cancelled at their current await, and only the cancel that stop() sends becomes Stopped. A timeout or task-group cancel stays a CancelledError. Stopped subclasses BaseException, so a broad except Exception in an agent loop doesn’t swallow it. A side effect wrapped in commit() runs only under a valid token, and a stop pressed meanwhile waits for it to finish. A tool that returns after the stop has its result withheld with code stopped.after-return.
Every outcome writes a receipt with the tool, capability, risk, status, code, generation, argument and result fingerprints and duration. fingerprint.py hashes canonical JSON with sorted keys and JavaScript number formatting, and switches to HMAC-SHA256 when you pass fingerprint_key. If a receipt can’t be written, the guard latches the stop and re-raises.
The console’s backend uses the same StopController. ActionGateway is the only route into execution. PolicyEngine allows only fixture.replay, stop.enable and stop.reset. SyntheticExecutor holds a 4 s inspection window, checking its token every 100 ms, before it loads orbital-relay-recovery.json. The pause exists only so you can stop the run, and the fixture itself calls the drill invented. A stopped replay returns HTTP 423 with code denied.stop-during-execution and no result. The hosted demo is built with VITE_DEMO_MODE=true and runs engine.ts, a TypeScript port of the gateway, entirely in the browser.
The five guarantees
The package README states five guarantees and names a Python and a TypeScript test for each.- No side effect commits after the stop latches.
- A call admitted before any stop or reset never commits again and never returns a result.
- Pressing stop many times, from any number of threads, equals pressing it once.
- A stopped call halts at its first checkpoint after the latch, or at its current await if it is async.
- Once a capability’s budget is spent, no call to it executes.
_track in guard.py. The mutation runs aren’t recorded in the repository and were not repeated for this page.
Verify it
These ran on 18 November 2026 againstmain at 34e9dbc with Python 3.12 and Node.js 24.18. The pinned pytest versions in backend/requirements-dev.txt (9.2.0) and the guard[test] extra (9.1.1) conflict, so the single-venv install in the README fails. CI installs them in separate jobs, and so did this run:
54 passed in 12.68s. The backend suite printed 20 passed in 0.45s. npm test printed tests 28, pass 28, fail 0, and the typecheck and build passed. bash scripts/scan-secrets.sh printed No high-signal credential patterns found. The pip_audit and npm audit steps from scripts/check.sh were not run for this page. The verify workflow passed on 34e9dbc on 6 November 2026.
To see the gate and stop on real functions:
read_file({'path': '../../../etc/passwd'}) -> denied: denied.rule.path.inside-workspace and delete_file({'path': 'notes/plan.md'}) -> denied: denied.capability. The second hashed the Python standard library and printed stopped after 769 files, 208 ms in, a receipt with code stopped.in-flight and no result fingerprint, and next call while latched: denied.stop-active, 0 files hashed. The file count and time vary per run. guard/examples/http_fetch.py needs network access and was not run.
Limits
switchyard-guard0.1.0 isn’t on PyPI. You install it from a clone withpip install ./guard.- The gate sees the arguments a tool is called with, not what the tool does with them. A rule over
pathdoesn’t stop a tool that opens a different path inside. - A sync tool with no
checkpoint()calls runs to the end. The stop then withholds its result and blocks later calls. - Stop state and budgets live in one process. Two processes sharing a tool need a shared controller, which the package doesn’t provide.
- Receipts aren’t signed. Whoever can write the SQLite file can rewrite them, and an unkeyed fingerprint of a short value can be guessed.
- The console replays one invented drill and has no live integrations. The local API has no authentication and binds to
127.0.0.1by default. - The hosted demo keeps receipts in the browser tab, and they clear on reload.
- The only GitHub release, v1.0.0 from July 2026, predates the
guard/package and the TypeScript port, which landed in October 2026. - The README’s one-venv install command fails at
34e9dbcbecause twopytestpins conflict.
Source
- Repository
- Live demo
- Package README
- Architecture notes
- Security model
- CI workflow
- Stop core and budgets, PR #29
34e9dbc.