Skip to main content

recusal, deterministic governance for AI agents

recusal-openai-agents

PyPI CI python license

The Recusal gate for the OpenAI Agents SDK: every function tool call an agent proposes is judged by your policy before the tool runs, and a refused call never runs.

New to Recusal? It 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. A policy is a plain Python function: it is given the tool's name and its arguments and returns a list of findings. An empty list lets the call run; a failing finding refuses it and gives the reason. Writing a policy covers the two postures, allowlist and deny-list.

Before the tool runs. An agent proposes a tool call. Recusal, your policy with no model in it, decides. With no objection the tool runs. On a failing finding, or when the policy itself raises, the call is refused: the tool never runs and the reason goes back to the model. Every decision can be written to a hash-chained audit log, if you pass one.

This is a separate distribution from recusal. The kernel has zero runtime dependencies and a frozen compatibility perimeter; this package carries the SDK dependency and its own version, so an SDK release never forces a release of the kernel.

Install it from PyPI:

pip install recusal-openai-agents

Requires Python 3.10+ (the SDK's minimum), recusal>=0.14.0 and openai-agents>=0.24.0. It is tested on every pull request against exactly openai-agents==0.24.0 with openai==3.49.0, and weekly against the newest releases.

The package ships inline types (py.typed) for your editor and type checker.

Use

from agents import Agent, function_tool
from recusal import Finding
from recusal_openai_agents import gated_agent


@function_tool
def run_sql(sql: str) -> str: ...


def policy(tool_name, tool_input):
    sql = tool_input.get("sql", "")
    if tool_name == "run_sql" and sql.lstrip().upper().startswith("DELETE"):
        return [Finding.fail("no_deletes", severity="CRITICAL", message="DELETE is not allowed")]
    return []


agent = gated_agent(Agent(name="assistant", tools=[run_sql]), policy)

gated_agent returns a copy of the agent with a Recusal tool input guardrail on every function tool. A refused call's output is Recusal's reason, which the model reads on its next turn. The tool does not run. A policy that raises refuses the call (fail closed). Runner.run, Runner.run_streamed and a human approval (needs_approval) all pass through the guardrail, which runs when the tool is about to execute, after any approval.

The gate judges the arguments as the SDK prepares them from the tool's schema, defaults included, and refuses a tool whose schema transforms its input after validation, since what would execute could not be judged.

Build the agent completely, then gate it. A tool appended to the gated agent's list afterwards is not gated. gate_tools(tools, policy) gates a list of tools directly.

Put every decision on the record

from recusal.audit import AuditLog
from recusal_openai_agents import audited_agent

log = AuditLog(path="decisions.jsonl")
agent = audited_agent(Agent(name="assistant", tools=[run_sql]), policy, log)

audited_tools(tools, policy, log) is the list form. Each call a guardrail sees, allowed or refused, is one hash-chained entry labeled openai_agents.tool_input_guardrail with the SDK's tool call id and a SHA-256 fingerprint of the arguments (never the arguments). If the log cannot be written the call is refused. Check the log with recusal audit verify decisions.jsonl.

The audited forms are the plain ones with a recording passed in, so there is one decision path.

What the gate refuses, and what it does not see

gated_agent raises at construction for an agent that can run something the guardrail never sees. The rule is default-deny:

  • Any tool that is not a FunctionTool: hosted tools that run on OpenAI's servers (web search, file search, code interpreter, image generation, hosted MCP, tool search) and local ones the SDK executes itself (shell, apply patch, computer, custom). A tool type added in a later SDK release is refused too.
  • MCP servers attached with mcp_servers=, and handoffs to other agents.
  • A sub-agent behind agent.as_tool(...) whose own tools are not gated. Gate the sub-agent first, gated_agent(sub, policy).as_tool(...), and the parent accepts it.
  • Agent subclasses such as SandboxAgent, which add tools of their own at run time.

Not on the audit log: a call the SDK rejects before the guardrail runs. A tool the agent does not have raises ModelBehaviorError in the SDK, and nothing runs.

Compatibility

This package is outside the kernel's frozen perimeter (STABILITY.md, Integrations). Its public names are the ones in recusal_openai_agents.__all__. When an SDK release changes what the guardrail is handed, this package gets a release and the kernel does not.

A runnable offline demonstration, with the SDK's scripted model and no API key, is examples/openai_agents_gate.py and examples/openai_agents_audit.py.

More

One kernel, eight adapters. Each adapter package depends on recusal: recusal-crewai, recusal-google-adk, recusal-langchain, recusal-langgraph, recusal-openai, recusal-openai-agents, recusal-openai-agents-mcp and recusal-pydantic-ai. recusal-langchain also depends on recusal-langgraph, and recusal-openai-agents-mcp on recusal-openai-agents. The kernel depends on nothing.

An arrow means "depends on". No arrow leaves the kernel, so a framework's breaking change is answered by a release of that framework's adapter, not by a release of the kernel.

Licensed under Apache-2.0.

Metadata

Release files for recusal-openai-agents 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for recusal-openai-agents 0.1.2
File Size Uploaded Provenance Actions
recusal_openai_agents-0.1.2.tar.gz 16.9 kB With provenance Details for recusal_openai_agents-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for recusal-openai-agents 0.1.2
File Interpreter ABI Platform Actions
recusal_openai_agents-0.1.2-py3-none-any.whl Python 3 none any Details for recusal_openai_agents-0.1.2-py3-none-any.whl

Total release size: 33.7 kB

Release files / recusal_openai_agents-0.1.2.tar.gz

Download URL recusal_openai_agents-0.1.2.tar.gz
Size 16.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ae6bfd9e7b034cd330735efe2dd62dff49065b959264cfad3a031c8aad8deac8
BLAKE2b-256 checksum
How to use checksums
9d825d15ca294275620494a27dc67e8c37f9a60450289ead55a749cfb4fed779
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 Nov 20, 2026.

Transparency log

Release files / recusal_openai_agents-0.1.2-py3-none-any.whl

Download URL recusal_openai_agents-0.1.2-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
05e5bd4ceca85d3aea2920a032df56f93f1410f0da4737a4857afc0cac697574
BLAKE2b-256 checksum
How to use checksums
ced6880bd40a6f96d243fbacb9314f5cfa84859de45e3a05deb88c3458c0f472
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 Nov 20, 2026.

Transparency log

Security for recusal-openai-agents 0.1.2

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.

Select from 2 files

Attestation for recusal_openai_agents-0.1.2.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 Nov 20, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page