Skip to main content
Attesta provides two integration points for the OpenAI Agents SDK:
  1. attesta_approval_handler — a Runner-level approval handler that gates all tool calls across the entire run.
  2. AttestaGuardrail — an Agent-level tool guardrail that evaluates individual tool invocations.

Installation


Approval Handler (Runner-level)

attesta_approval_handler() returns an async handler that matches the approval_handler signature expected by Runner.run(). Every tool call during the run is evaluated through Attesta before execution.

API

Returned handler signature:
  • Returns True to allow the tool call
  • Returns False to deny (the SDK skips execution)

Full Example

When the agent calls deploy_tool, Attesta:
  1. Builds an ActionContext from the tool name and arguments
  2. Scores the risk (the word “deploy” + “production” arguments will score HIGH)
  3. Presents the appropriate challenge to the human operator
  4. Returns True (approved) or False (denied) to the SDK
The **kwargs passed to the handler are forwarded as hints in the ActionContext. This means any extra metadata the SDK provides is available to the risk scorer.

Tool Guardrail (Agent-level)

AttestaGuardrail is a callable class that matches the tool_guardrails interface on the Agent class. It evaluates each tool invocation and returns None to allow or a dict with an "error" key to deny.

API

Callable signature:

Full Example


Combining Both

You can use both integration points simultaneously. The approval handler provides a global gate, while guardrails provide per-agent control:
When both are active, tool calls are evaluated twice — once by the guardrail and once by the approval handler. For most use cases, choose one or the other. Use the approval handler for broad coverage across all tools, or guardrails for fine-grained per-agent control.

How Denial Works

When a tool call is denied:
  • Approval handler returns False. The OpenAI Agents SDK skips the tool execution entirely. The agent does not receive any output for that tool call.
  • Guardrail returns {"error": "Denied by Attesta (risk: <level>)"}. The SDK passes this error back to the agent, which can then decide how to proceed (retry with different parameters, suggest alternatives, or inform the user).
Guardrails are generally preferred over approval handlers because they provide the agent with an explanation of why the action was denied. This allows the agent to suggest alternatives to the user rather than silently failing.

Custom Attesta Configuration

Pass a fully configured Attesta instance to control risk scoring, challenge types, and trust behavior:

Anthropic Claude

Gate Claude tool_use blocks

LangChain

Wrap LangChain tools and LangGraph nodes