OpenAI Agents SDK Middleware & Guardrails (Python)
OpenAI Agents SDK Middleware & Guardrails (Python)
Section titled “OpenAI Agents SDK Middleware & Guardrails (Python)”Latest: 6.8.1 Upstream: https://github.com/openai/openai-python | https://platform.openai.com/docs
Middleware Chain
Section titled “Middleware Chain”from typing import Awaitable, CallableNext = Callable[[str], Awaitable[str]]Middleware = Callable[[str, Next], Awaitable[str]]
async def policy_mw(inp: str, next_call: Next) -> str: if "ssn" in inp.lower(): raise ValueError("Policy violation") return await next_call(inp)