Lightweight, extensible governance for AI agent tool calls, Claude-native and framework-neutral: an independent, deterministic verifier that can refuse to certify a tool call before it runs. Builders cannot grade their own work.
pip install recusal==0.12.2 Copy PIP instructions
Recusal checks each tool call an AI agent proposes against your policy, and refuses the unsafe or unapproved ones before the tool runs. No model makes that decision; your policy functions do.
It drops into Claude Code as a hook, MCP tool calls included, gates a Claude Messages API loop or any Python agent loop, and a tested example gates LangGraph's ToolNode with one argument. Zero runtime dependencies, Python 3.9+.
Verbatim transcripts, rendered: a live Claude Code session where the repo's own hook refuses rm -rf under --dangerously-skip-permissions, then pip install recusal && recusal demo --scenario wrong-subject, no API key and no clone. The second panel is rendered from that command's captured output by tools/render_demo_gif.py, so "verbatim" is reproducible rather than asserted.
pip install recusal recusal demo Four scenarios, offline and deterministic: a write to the wrong customer refused before the tool runs, the shipped deny-list refusing rm -rf and its own uninstall while an ordinary command defers, a pinned MCP catalog refusing a post-approval rug pull, and a valid call refused because its delegated authority expired. recusal demo --list names them; --scenario runs one. (Its exit code is not a verdict: recusal verdict is the command whose exit code adjudicates.)
The long form, annotated and worth reading, is in the repository:
git clone https://github.com/philpaz/recusal && cd recusal python examples/claude_refusal.py # a Claude agent stages a write to the WRONG # customer; the gate refuses before the tool runs python examples/gallery.py # the same gate across the OWASP agentic failure modes python examples/mcp_security_demo.py # an approved MCP launch command changes; verification # refuses BEFORE the substituted command executes Deterministic and offline: the same normalized evidence and explicit policy inputs, under the same recusal implementation version, produce the same verdict, including the no.
The core is plain Python with no dependencies, so it gates any agent loop that lets you check a tool call before it runs. Each row says how far that is proved today: Tested means a runnable example with its own tests in this repository's CI. Coming links the pull request or claimed issue where the work is happening. Wanted links an open issue nobody has taken yet: comment there to pick it up.
xAI documents its Grok API as using the same request formats as OpenAI's, so #81 is also where Grok support will start. Want a runtime that isn't listed? Open an issue.
What no local gate can see. Some tools run on the model provider's servers, such as hosted web search, a hosted code interpreter or hosted MCP. Those calls never pass through your code, so neither Recusal nor any other local gate can refuse them.
An autonomous agent proposes a tool call, and then, in most stacks, something from the same model family effectively decides whether that action is acceptable. When the agent runs in auto or bypass mode, even that check thins out: what stands between a proposed rm -rf, a wrong-customer write, or an unapproved MCP tool and its execution is the model's own judgment about its own action.
A judge recuses themselves from a case they cannot impartially decide; the same principle governs autonomous agents: the thing that generates the work must never be the thing that certifies it.
Lightweight (zero dependencies) · extensible (a check is just a function that returns a finding) · Claude-native (a Claude Code hook, a Claude Messages API loop or Managed Agents as a tool gate) · framework-neutral (the core works in any agent loop; in LangGraph it is ToolNode(tools, wrap_tool_call=recusal_gate(policy))).
Recusal places deterministic policy between the proposed action and its execution. No model makes the decision: explicit findings fold into a PASS / RETRY / FAIL verdict, and a non-clean verdict refuses before the tool runs. Concretely:
The same normalized evidence and policy inputs, under the same recusal version, produce the same verdict, including the "no".
Builders generate. Recusal certifies. Refusal is a feature.
pip install recusal Claude Code, drop-in PreToolUse hook Refuse destructive tool calls before Claude Code runs them, even in auto / bypass mode.
python -m recusal init # or: recusal init scaffolds .claude/hooks/recusal_gate.py (the deny-list starter, edit it, it's yours) and registers the fail-closed launcher in .claude/settings.json, merging with (never clobbering) an existing file; re-running is a no-op, and an existing gate file is never overwritten. --posture allowlist scaffolds the default-deny variant instead. Claude Code asks you to confirm the new hook on the next session: a permission-changing hook is a deliberate step.
Or as a plugin (one gate across every project, no per-project setup):
claude plugin marketplace add philpaz/recusal claude plugin install recusal-gate@recusal # self-contained: the plugin vendors the exact recusal runtime it executes # (POSIX launcher: macOS/Linux/Windows-with-Git-Bash) The plugin ships the same deny-list shim and adjudicates with its own vendored copy of the package - no pip install step. A missing, substituted (an ambient package instead of the vendored copy), or version-mismatched runtime refuses every tool call rather than silently disabling itself. For a policy tailored to one project, prefer python -m recusal init and edit the scaffolded gate. Under the managed setting allowManagedHooksOnly, Claude Code blocks plugin hooks unless managed enabledPlugins force-enables that exact recusal-gate@recusal ID (settings reference): an installed but not force-enabled gate would not run.
For production, pin the runtime the gate runs on: a dedicated venv with pip install "recusal== ", registered explicitly, protected from agent writes. pip install recusal is the quick start, not the governance deployment. (Inside a governed session, the deny-list refuses package-manager commands that uninstall, reinstall, or shadow the recusal package: managing the gate's own runtime is the operator's job, outside the session.) One named residual, stated in full in docs/HOWTO.md: hook timeout is fail-open. Claude Code documents that a PreToolUse command hook canceled at its timeout (600 seconds unless the registration sets timeout) "doesn't block the tool call" and the call continues through the normal permission flow (hooks reference). Recusal's shipped policies adjudicate in milliseconds; keep custom policies fast and bounded, and keep a native deny rule for anything that must hold even if the gate stalls.
Verifying what you installed is a first-class step, not an afterthought: docs/VERIFY.md shows how to check the build provenance, the release-boundary Sigstore signatures, and PyPI's own attestation yourself, negative controls included.
Prefer to see exactly what it writes? The manual path is the same two pieces. Register a hook in .claude/settings.json:
{ "hooks": { "PreToolUse": [ { "matcher": ".*", "hooks": [ { "type": "command", "command": "[ -n \"$CLAUDE_PROJECT_DIR\" ] || { echo 'gate: CLAUDE_PROJECT_DIR is empty, so the gate script cannot be found; failing closed' >&2; exit 2; }; for p in python3 python py; do \"$p\" -c 'import sys; sys.version_info >= (3, 9) or sys.exit(1); import recusal' 2>/dev/null && { \"$p\" \"$CLAUDE_PROJECT_DIR/.claude/hooks/my_gate.py\"; rc=$?; [ \"$rc\" = 0 ] || { echo 'gate: hook did not run cleanly; failing closed' >&2; exit 2; }; exit 0; }; done; echo 'gate: no python>=3.9 that can import recusal; failing closed' >&2; exit 2" } ]} ]}} The command runs the first python3 → python → py that is >=3.9 and can import recusal (so an interpreter without the package is skipped, not chosen), and fails closed. The exit-code semantics, stated exactly: Recusal's normal refusal exits 0 with permissionDecision: "deny" JSON, which Claude honors as a block; a clean verdict exits 0 with no output and defers to Claude's normal permission flow; exit 2 is Claude's blocking failure signal, and any other nonzero exit is a non-blocking error that lets the tool call proceed. That last rule is why the launcher exists: a bare python3 on a Windows machine (no python3 on PATH), a python that is Python 2, or a hook that raises at import would each be a nonzero-but-not-2 failure, i.e. a silently disabled gate. The loop coerces exactly those gate-process failure modes - missing interpreter, unsupported interpreter, import failure, nonzero gate-process exit - into exit 2, so they refuse instead of waving the call through. It does not cover Claude-level hook cancellation or the hook timeout, which is fail-open (above).
Windows: shell-form hooks run under Git Bash when it is installed, and Claude Code falls back to PowerShell when it is not - where this POSIX loop is a parse error with a non-blocking exit code, i.e. the gate silently disables (live-verified). recusal init therefore registers a PowerShell-native launcher with an explicit "shell": "powershell" on Windows; the POSIX form above is for macOS/Linux and Windows-with-Git-Bash. For a settings.json shared across operating systems, recusal init --launcher both registers the pair, and recusal doctor validates the registered launcher against the host.
A policy is a function; the gate does the rest:
# my_gate.py from recusal import Finding from recusal.claude_code import run_pretooluse_hook def policy(tool_name, tool_input): if tool_name == "Bash" and "rm -rf" in tool_input.get("command", ""): return [Finding.fail("destructive_bash", severity="CRITICAL", message="refusing rm -rf")] return [] # no opinion → defer to Claude Code's normal permission flow run_pretooluse_hook(policy) A clean verdict defers (Recusal adds refusals; it never strips Claude Code's own prompts). A non-clean verdict denies, with the reasons. See examples/claude_code_gate.py.
Pick the posture by your channel, not by a ranking.
Allowlist mode (default-deny) is the enforcement posture: name the affirmatively-safe calls, refuse everything else. It fits a narrow, enumerable, high-stakes channel: nothing runs unless listed, and bare interpreters and shell metacharacters are refused, which closes the documented command-construction and bare-interpreter bypass classes by construction (pinned as tests). Within a correctly registered routed tool channel, an unapproved capability is refused by default rather than inferred safe; what sits outside that channel is named in SECURITY.md. One more honest line: the default-safe tools are nonmutating, not authorized for all data - cat can read a credential file - so add path- and subject-level read rules where confidentiality matters. The trade is friction and maintenance: you enumerate and grow the capability set, and it fails toward refusal until you do.
from recusal.claude_code import allowlist_policy, run_pretooluse_hook run_pretooluse_hook(allowlist_policy(writable_root="./workspace")) The deny-list is the low-friction door: name the known-bad calls, defer everything else. It drops into a broad, open-ended channel with almost no friction and needs no inventory of your tools, which is why this repo dogfoods it (a general-purpose dev repo runs an unbounded set of legitimate commands). Its boundary is inherent, not a defect: a literal matcher can be obfuscated past, and python script.py runs code no string check ever reads, so a deny-list never earns "cannot be subverted." It also refuses package-manager mutation of the enforcement package itself (pip uninstall recusal and install-time shadowing, across the pip / python -m pip / uv spellings and their option, value, and Windows launcher forms), comparing canonical distribution identities and refusing a merely name-containing source (./fake-recusal) toward safety. Exactly what is and is not covered, form by form: SECURITY.md and docs/HOWTO.md.
Neither is "better" in the abstract: a deny-list refusing the unknown would grind a broad channel to a halt, and an allowlist deferring the unknown would defeat the point of a high-stakes one. Choose by the channel. Both ship, and both are pinned as tests.
Don't start from a blank policy. docs/COOKBOOK.md has copy-paste recipes (destructive shell, unscoped SQL, secret-file writes, wrong-subject writes, egress allowlists, injection quarantine, action budgets) that drop straight into the hook above.
Recusal governs this repository exactly this way: a real hook refuses rm -rf, force-pushes, and secret-file writes to its own maintainers. Verbatim, reproducible, CI-locked proof: docs/PROVEN.md.
MCP server tools reach Claude Code as ordinary tools (mcp__ __ ), so the .* matcher above already routes every MCP call through the same policy(tool_name, tool_input) seam: no MCP-specific adapter, no extra wiring. Destructive-operation refusal, repository/record scope, write-path confinement, egress and action budgets, and the tamper-evident audit record apply to MCP exactly as to Bash; in allowlist mode an MCP tool is refused unless affirmatively named.
The three MCP tool-call boundaries, stated plainly. A call-time policy adjudicates the proposed tool name and arguments; MCP has two more boundaries, and Recusal covers each with its own evidence:
Transport and authorization threats (confused deputy, token passthrough, session hijacking) are the MCP specification's own Security Best Practices layer, complementary to this gate, neither replaces the other.
The discovery boundary gets its own deterministic control. The model chooses tools by reading their declared descriptions, so a poisoned declaration steers the agent before any call exists for a call-time policy to see. Pin what a human approved, then refuse represented drift:
recusal mcp pin --claude-config .mcp.json --approve-server-launch # review once, pin recusal mcp verify --claude-config .mcp.json --manifest mcp-manifest.json # CI / session start: same source, instructions, and declarations, or refuse verify fails closed (a missing manifest or an unreachable pinned server is a refusal, never a clean-looking pass), and the pin enforces at call time: recusal.mcp.manifest_policy("mcp-manifest.json") refuses any mcp__server__tool call that was never pinned. No pin, no MCP. Opt-in strict modes: pin --resolve-executable also pins the {path, sha256} of the file each stdio command resolves to (a swapped executable behind an unchanged command template refuses), and pin --scope LABEL stores an operator-declared observation-scope label whose stability is verified across re-pins (a changed scope is a named WARNING; the label's truth is never verified). The honest boundary, in one line: verification is point-in-time over the configuration artifact you supply, not continuous attestation of Claude's effective MCP environment; the full statement, with every named residual (transport, OAuth, plugin runtime identity, list_changed, roots), is docs/MCP.md.
Runnable: examples/mcp_governance.py and examples/mcp_manifest_rugpull.py (both offline). Recipes: docs/COOKBOOK.md §12-§14.
Pair any verdict with an append-only, hash-chained log: every decision on the record, and an in-place edit or reordering of any entry with a surviving successor is detectable (catching tail-truncation, a tail-suffix rewrite, or a forged append by a write-access attacker needs an external anchor, see recusal.audit):
from recusal import AuditLog, verify audit = AuditLog(path="audit.jsonl") audit.append(verdict, action={"tool": "Bash", "command": "rm -rf /"}) ok, problems = verify(audit.entries) # False if an entry with a later entry was edited/reordered In the Claude Code hook it is one argument: run_pretooluse_hook(policy, audit=AuditLog("audit.jsonl", resume="tail")) puts every adjudication - defer, allow, and deny - on the chain, with the proposed tool_input bound by SHA-256 fingerprint, never embedded, and an unwritable log failing closed to a deny (the record is part of the control). Declared policy_id/policy_version values are caller-supplied labels unless you separately bind them to a protected source artifact; the record provides the identifiers needed to locate the policy and evidence for replay, it does not by itself make arbitrary policy execution replayable. resume="tail" recovers the chain head from the final record without loading or scanning the full log, and file-backed appends are serialized with an inter-process lock, so hooks for parallel tool calls extend one chain instead of forking it.
Any other runtime gets the same record from decide: decide(tool_name, tool_input, policy, audit=log, surface="my_runtime.tool_gate", tool_use_id=call_id) writes the same entry through the same recorder, with the same fail-closed rule. surface is required whenever audit= is passed and names the runtime that adjudicated, so every entry says where its decision was made; claude_code.pretooluse is reserved for the hook. Without audit=, decide is the same pure function it has always been.
The external anchor is first-class: AuditLog(..., sinks=[...]) mirrors every committed entry to any object with a write(entry) method (a WORM bucket, another host, a signer; recusal.AuditSink is the protocol), and a sink failure surfaces as a failed append, so the hook fails closed to a deny rather than adjudicating off the record. Each entry carries its seq and hash, so a sink holds the head anchor (seq + 1, hash) directly. Opening a log can then refuse instead of trusting: AuditLog(path, verify_on_open=True) raises AuditIntegrityError rather than extend a file that fails strict verification, and AuditLog(path, expected_head=(count, hash)) also refuses truncation, a tail-suffix rewrite, or forged appends against that externally held head.
Run python examples/audit_sink.py for a custom sink example that mirrors entries, saves the head, and refuses a truncated log; its local mirror demonstrates the interface, not protected external storage.
Deterministic, stdlib-only, and designed to support OWASP Agentic logging and EU AI Act Article 12 record-keeping: in a regulated deployment, this can provide one auditable decision artifact within the broader system of records, controls, evidence retention, and deployment governance.
The reflex fix for agent safety is another model asking "does this action look OK?", but a judge from the same family shares the builder's blind spots and drifts with it: that is a conflict of interest, not a control. Recusal is an independent, deterministic authority instead: no model in the decision path, a verdict you can replay and audit, and a refusal that holds. "Independent" means the verdict is produced outside the model's decision path; deployment isolation (who owns the config, the file permissions, the runtime) remains the adopter's responsibility.
The published evidence (models faking passing tests, benchmarks gamed by intercepting the evaluator, and the stated limits of Anthropic's own same-family safety layer) is laid out in docs/WHY.md, every source verified in docs/REFERENCES.md.
One object model, one pipeline. Checks (or your own evidence) produce Findings; compute_verdict folds them into a Verdict; and the Verdict drives every surface: the gate refuses, the audit log records, the classifier routes.
data / a proposed agent action / a tool call │ [ checks ] emit Findings (recusal.checks, recusal.authorization, or your own) │ compute_verdict() fold findings → one Verdict (PASS / RETRY / FAIL) │ Verdict │ │ │ │ │ └─ recusal.classify route the failure (retry / refuse / ask-human / …) │ └───── recusal.audit tamper-evident, hash-chained record └───────── recusal.claude(_code) allow or refuse the tool call recusal.gates staged G0-G8 release decision Module What it is recusal.evidence the contract, Finding, Verdict, Severity, Decision, compute_verdict, and the two named empty-evidence intents evaluate_policy / certify_evidence recusal.checks built-in deterministic checks that turn data into Findings recusal.authorization authorization for one exact action: ActionRequest, AuthorizationContext (supplied evidence, each item with provenance), Constraints, nine named dimension checks, certify_authorization (a required dimension with no finding refuses), and the digest-bound DecisionReceipt. Reads no clock, keeps no state, signs nothing recusal.claude · recusal.claude_code gate a Claude agent's tool calls (Messages API manual loop, Managed Agents, Claude Code hook) recusal.deny_list · recusal.claude_code.allowlist_policy ready-made policies: a reference deny-list (refuse known-bad) and default-deny allowlist recusal.mcp · recusal.mcp_fetch MCP tool and server-instruction integrity: pin supported source templates, observed server instructions, and complete tool declarations; refuse represented drift (diff_observation); enforce approved runtime tool names at call time (pure kernel); collect a live catalog over stdio (fetcher, the one module that spawns a process). Full boundary statement: docs/MCP.md recusal.audit tamper-evident, hash-chained log of every verdict recusal.classify deterministic failure classifier + router recusal.gates staged G0-G8 release-gate adjudication, compute_verdict at each checkpoint Zero runtime dependencies, standard library only.
from recusal import compute_verdict from recusal.checks import row_count, null_rate, referential_integrity verdict = compute_verdict( [ row_count(users, min_rows=1), # CRITICAL if empty null_rate(users, "email", max_rate=0.10), # ERROR if too sparse referential_integrity(orders, users, fk="user_id", pk="id"), # CRITICAL on orphans ] ) if verdict.refused: raise RuntimeError(verdict.reasons()) Worst finding Verdict Meaning CRITICAL failure FAIL Terminal. The work is wrong. Do not retry. ERROR failure RETRY Recoverable. Retry once, with the failures as context. WARNING / INFO only PASS Proceed. Warnings recorded, info kept as metrics. An empty findings list is the question most gates get wrong, so the kernel names both answers instead of picking one silently. evaluate_policy(findings) reads findings as objections: nothing raised means no objection, PASS. certify_evidence(findings) reads them as proof: nothing presented certifies nothing, so it refuses with a synthesized no_evidence failure. compute_verdict is unchanged and identical to evaluate_policy. Pick by what your findings mean (docs/EVIDENCE.md).
Recusal uses PreToolUse, Claude Code's native pre-execution policy seam, and it is intentionally ONE layer in a broader control stack, not a replacement for the others. Claude native permissions own broad allow/ask/deny rules (a native deny applies regardless of any hook decision). Claude sandboxing constrains what an allowed command can touch after it runs. Managed settings own organization-controlled policy, hook distribution, and MCP server restrictions (allowedMcpServers bounds the servers users add, and is authoritative only with allowManagedMcpServersOnly: true; since Claude Code 2.1.259 it no longer filters managed-mcp.json servers, other than those using ${VAR} expansion; deniedMcpServers still subtracts from all of them). Claude MCP configuration owns transport, OAuth, credentials, and endpoint connectivity. Recusal owns deterministic evidence adjudication: explicit findings become PASS/RETRY/FAIL with no model in the decision path, a clean verdict defers to Claude's remaining permission flow by default, and a non-clean verdict denies before execution. The strongest deployment is layered:
managed settings configure the allowed control surface tool proposal -> Recusal PreToolUse adjudication -> Claude native permission rules and prompt -> Claude sandbox / OS boundary -> approved tool or MCP execution (audit records the Recusal decision separately, externally anchored) The diagram shows execution order (PreToolUse runs before the permission prompt); enforcement precedence is deny-wins across the hook and native permission layers - a native deny applies regardless of any hook decision, and a blocking hook takes precedence over a native allow.
In a manual agent loop, gate each tool call and hand Claude an is_error tool_result on a refusal; it self-corrects:
from recusal.claude import gate_tool_use allow, refusal = gate_tool_use(tool.id, gather_evidence(tool), tool_name=tool.name) if not allow: results.append(refusal) # is_error=True → Claude adapts else: results.append( { "type": "tool_result", "tool_use_id": tool.id, "content": execute_tool(tool.name, tool.input), } ) Runnable: examples/claude_agent_live.py (real API) and examples/claude_refusal.py (offline, no key). For Managed Agents always_ask, recusal.claude.tool_confirmation is the deterministic decider, building the user.tool_confirmation event Anthropic documents; under the auto policy it decides only the calls the server pauses on (see docs/HOWTO.md).
The Claude adapters are conveniences; the zero-dep core is framework-neutral. examples/agent_loop.py gates a plain propose → gate → act loop whose only import is recusal. The same compute_verdict seam fits any runtime that lets you check a call before the tool runs; Works with lists what is tested today and what is coming.
For a concrete LangGraph integration, examples/langgraph_gate.py puts existing @tool functions unchanged into LangGraph's ToolNode and attaches recusal_gate(policy) with wrap_tool_call, so recusal.claude_code.decide runs immediately before each individual tool call. Async graphs use recusal_agate(policy) with awrap_tool_call and ainvoke. It is offline and deterministic (no model or API key), requires Python 3.10+, and is tested with exactly langgraph==1.2.12 and langchain-core==1.6.5. LangGraph remains an example-only dependency; the Recusal package and its Python 3.9+ support are unchanged.
For LangChain's create_agent middleware, examples/langchain_agent_gate.py reuses the same recusal_gate(policy) through wrap_tool_call without a second policy implementation. It is offline and needs Python 3.10+ with langgraph==1.2.12, langchain-core==1.6.5 and langchain==1.4.3 (example-only pins). List the gate last in middleware=, so it judges the call exactly as it will run: the first middleware is the outermost, and one listed after the gate (an argument rewriter, a human-in-the-loop edit, LLMToolEmulator) acts on a call the gate never saw. For agent.ainvoke, use wrap_tool_call(recusal_agate(policy)); the sync gate alone raises there and runs nothing.
For the OpenAI Agents SDK, examples/openai_agents_gate.py adds recusal_guardrail(policy) to each function tool as a tool input guardrail, which the SDK runs immediately before the tool executes. A refusal becomes the call's output, so the model reads Recusal's reason and the tool never runs. Gate a finished agent with gated_agent(agent, policy): it returns a gated copy, and it refuses, rather than skips, anything the guardrail cannot see. That means hosted tools and the SDK's other non-function tools (shell, computer, apply patch and the rest), mcp_servers, handoffs, an agent.as_tool(...) whose sub-agent is not itself gated, and Agent subclasses such as SandboxAgent. Runner.run, Runner.run_streamed and calls a person approved through needs_approval are all judged when the tool is about to run. It is offline (the SDK's own ScriptedModel, no API key) and needs Python 3.10+ with openai-agents==0.24.0 and openai==3.34.0 (example-only pins).
What the gate guards, and what it doesn't. It judges each call the model proposes, the tool name and its arguments, before that tool runs. A policy covers only the tools it names: examples/sql_scope_policy.py inspects run_sql and query, so a SQL tool under another name passes through until the policy names it. And the gate sees the proposed call, not what a tool does internally once it runs, so a tool that builds a command or query at runtime needs checks of its own.
python examples/gallery.py runs the gate against the common autonomous-agent failure modes:
scenario OWASP verdict outcome wrong-subject write ASI03 Identity Abuse FAIL REFUSE destructive file delete ASI02 Tool Misuse FAIL REFUSE unscoped SQL mutation ASI05 Code Execution FAIL REFUSE data exfiltration ASI01 Goal Hijack FAIL REFUSE coverage floor quality gate RETRY BLOCK (retry) runaway action volume ASI08 Cascading RETRY BLOCK (retry) compliant write - PASS ALLOW The tiers are the policy: destructive things REFUSE terminally; recoverable ones BLOCK with a retry; a clean call passes. (Same policies power the demo and the test suite.)
CI is, by construction, not the session that did the work, which makes it the natural place for a recusal verdict. The same kernel runs as a command line with blocking exit codes (PASS 0, RETRY 1, FAIL 2; any operational error exits 2, failing closed):
recusal verdict findings.json --json # adjudicate any tool's findings; nonzero blocks the job recusal audit verify audit.jsonl --expect-head "42: " # a missing log is NOT an intact log recusal doctor # "the gate silently isn't installed" fails CI, not prod Or as a GitHub Action (action.yml, dogfooded by this repo's own CI, including the negative case: a tampered audit log must make the gate refuse):
- uses: actions/setup-python@v6 with: python-version: "3.12" - uses: philpaz/recusal@v0.12.2 # or pin an immutable commit SHA for stronger provenance with: findings: reports/findings.json # RETRY exits 1, FAIL exits 2 → the merge is blocked audit-log: reports/audit.jsonl doctor-dir: "." The action ref selects the implementation: the action force-installs the recusal bundled with the selected ref, replacing whatever happens to be on the runner, so pinning the action pins the code (proven in CI on a clean runner and against a deliberately conflicting preinstall). The two escape hatches are explicit inputs that name the provenance trade: version: installs a named PyPI release, and use-installed: "true" keeps a deliberately preinstalled checkout.
Given nothing to adjudicate, the action exits 2 rather than pass vacuously: an evidence set that proves nothing certifies nothing.
A refusal or failure is only useful if you know what to do next. The classifier says what kind of failure it is and where it routes, deterministically, with no model:
from recusal import classify_failure c = classify_failure("Traceback ... TypeError: 'NoneType' object") c.failure_class # "code_bug" c.route # "fix-code" Default taxonomy (extend or replace it): transient → retry · policy_violation → refuse · prompt_injection → quarantine · code_bug → fix-code · data_shape → fix-data · data_missing → fetch-data · spec_ambiguity → ask-human. Unmatched failures fall back to ask-human; it never guesses. classify_verdict(verdict) routes a non-PASS verdict.
New here? The quick objections (do I need this? doesn't Claude already do it? is it ready to use?) are answered in the docs/FAQ.md. The plain-terms "so what": docs/WHY.md.
Full documentation index: docs/. MCP governance in full, boundaries and residuals included: docs/MCP.md. Comparison with the landscape: docs/LANDSCAPE.md. The principles and why each helps: CONSTITUTION.md. The contract: docs/EVIDENCE.md. Usage & extending: docs/HOWTO.md · docs/EXTENDING.md. Copy-paste policies: docs/COOKBOOK.md. A full worked configuration: docs/EXAMPLE.md. Proof it governs itself: docs/PROVEN.md. Verify the artifacts yourself: docs/VERIFY.md. What will not move under you, and what 1.0 has to earn: STABILITY.md.
pip install -e ".[dev]" pytest -q The suite is the argument: per-surface edge cases, adversarial red-team tests against the dogfooded hook, drift locks that fail when a document and the code it describes disagree, and Hypothesis property tests over the frozen kernel (verdict monotonicity and order-independence, the documented decision fold, fail-closed string coercion, strict-mode refusal of outcome-less evidence, fingerprint stability). Hypothesis is a dev extra, derandomized in CI; runtime dependencies stay at zero.
Contributions are welcome. Recusal is deliberately small, and the bar is keeping it that way (no model in the verdict path, no runtime dependencies, don't grow the kernel). Read CONTRIBUTING.md and the CODE_OF_CONDUCT.md first. Security reports go through SECURITY.md, privately.
Thank you to the people who have made Recusal better:
Want to join them? Issues labeled good first issue are a friendly place to start; see the open issues.
Built by Philip Paz. Messages are open, especially from teams running agents in regulated environments, and doubly so if you wired the gate in and found where it leaks (tell me here).
agent-governance agent-reliability agent-safety ai-agents ai-safety claude claude-code determinism guardrails llm runtime-governance separation-of-powers tool-use verifier
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
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 verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.




