Skip to main content

recusal-openai

The Recusal gate for a loop you own on the OpenAI API: every function call the model proposes is judged by your policy before your code runs it, and a refused call never runs. It covers the Responses API and Chat Completions with one decision function.

This is a separate distribution from recusal. The kernel has zero runtime dependencies and a frozen compatibility perimeter; this package carries the OpenAI 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

Requires Python 3.10+ (the SDK's minimum), recusal>=0.14.0 and openai>=3.34.0. It is tested on every pull request against exactly openai==3.34.0, and weekly against the newest release.

Use

from openai import OpenAI
from recusal import Finding
from recusal_openai import gate_function_calls


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 []


client = OpenAI()
response = client.responses.create(model=..., input=..., tools=...)
answers = gate_function_calls(response, {"run_sql": run_sql}, policy)
# pass ``answers`` as the next request's input

gate_tool_calls(completion, tools, policy) does the same for Chat Completions and returns role: "tool" messages. A completion requested with n > 1 carries alternative messages, so pass choice=<list position>; without it the gate refuses the completion before anything runs.

Each proposed call gets exactly one answer under its own id: the tool's result, or Recusal's reason. A policy that raises refuses the call (fail closed).

The gate binds the decoded arguments to the tool's signature with its defaults applied, judges that invocation, and calls the tool with exactly those arguments. A default the model omitted is therefore judged at the value the function would use.

Put every decision on the record

from recusal.audit import AuditLog
from recusal_openai import audited_function_calls

log = AuditLog(path="decisions.jsonl")
answers = audited_function_calls(response, tools, policy, log)

audited_tool_calls is the Chat Completions form. Each call the model proposes, run or refused, is one hash-chained entry labeled openai.responses.function_call or openai.chat_completions.tool_call with the API's own 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 functions call the plain ones, so there is one decision path.

What the gate refuses, and what it does not see

  • Refused with a reason, never run: arguments that are not valid JSON or not a JSON object, a tool the application does not have, arguments that do not bind to the tool, and a tool whose signature cannot be judged by name (variadic or positional-only parameters, an unsupported annotation, a default that is not JSON data).
  • Refused by raising, before anything in the turn runs: an output item or tool call of a type the gate does not handle (custom_tool_call, a hosted tool call, a type a later SDK adds), a call without an id, and a duplicate id. A turn refused this way writes no audit entry.
  • Not seen at all: hosted tools (web search, file search, code interpreter, image generation, remote MCP) run on the provider's side and never reach your loop.

Compatibility

This package is outside the kernel's frozen perimeter (STABILITY.md, Integrations). Its public names are the ones in recusal_openai.__all__. When an SDK release changes the response types the gate reads, this package gets a release and the kernel does not.

A runnable offline demonstration, with SDK-validated responses and no API key, is examples/openai_responses_gate.py and examples/openai_responses_audit.py.

Metadata

Release files for recusal-openai 0.1.1

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 0.1.1
File Size Uploaded Provenance Actions
recusal_openai-0.1.1.tar.gz 14.1 kB With provenance Details for recusal_openai-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 28.1 kB

Release files / recusal_openai-0.1.1.tar.gz

Download URL recusal_openai-0.1.1.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2859d7faf81c9c91d922fcd46ca2faec929f37e190591f883b3c21d8d42617ea
BLAKE2b-256 checksum
How to use checksums
5e6f5dd66a8f314b24f9fd4ebaa355895817f374dff4573998597f156d884e6f
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 14, 2026.

Transparency log

Release files / recusal_openai-0.1.1-py3-none-any.whl

Download URL recusal_openai-0.1.1-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0b02b67cc8532a0a9021d28409f1a609f7008426c9c97076772489fc1917b36c
BLAKE2b-256 checksum
How to use checksums
ad701f28f2a21fda8efcec1f9571d549e54498e959ea886ad32e06a717b68d83
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 14, 2026.

Transparency log

Security for recusal-openai 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.

Select from 2 files

Attestation for recusal_openai-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 Nov 14, 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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

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