Use the VerifiedOpenAI wrapper to add verified tool calls, structured output validation, and deterministic guards to OpenAI Assistants and agent workflows.
QWED Open Responses provides a verified wrapper for the OpenAI SDK.
Always pass at least one guard. VerifiedOpenAI without guards emits a UserWarning at construction: verification is fail-closed, so with zero guards every response fails verification and either raises ResponseBlocked (block_on_failure=True) or is returned unverified (block_on_failure=False).
The attached _qwed_verification result also exposes:
warnings: guard results that passed with warning severity
request_id: correlation ID when a request_id was supplied in the verification context
binding and verify_binding(): tamper-evidence tying the result to the exact response and guard list
timestamp: timezone-aware UTC timestamp with the +00:00 offset
from qwed_open_responses.middleware.openai_sdk import ResponseBlockedtry: response = client.chat.completions.create(...)except ResponseBlocked as e: print(f"Response blocked: {e.result.block_reason}") # Access the original response original = e.response # Access verification details for guard_result in e.result.guard_results: if not guard_result.passed: print(f" - {guard_result.guard_name}: {guard_result.message}")
Pass verification_context to chat.completions.create() or responses.create() to give guards trusted usage totals, such as the running total_cost and total_tokens for a session. VerifiedOpenAI removes verification_context from the request before calling OpenAI, so it never reaches the API. The context is then passed to every guard when the response is verified.
from qwed_open_responses import SafetyGuardfrom qwed_open_responses.middleware.openai_sdk import VerifiedOpenAI, ResponseBlockedclient = VerifiedOpenAI( api_key="sk-...", guards=[SafetyGuard(max_cost=10.0, max_tokens=50_000)],)try: response = client.chat.completions.create( model="gpt-4", messages=[{"role": "user", "content": "Summarize this report"}], verification_context={"total_cost": 9.50, "total_tokens": 48_000}, )except ResponseBlocked: # Response pushed the totals past a SafetyGuard budget limit ...
You can also call client.verify(response, context={...}) directly.
# For the new OpenAI Responses API (when available)client = VerifiedOpenAI(api_key="sk-...")response = client.responses.create( model="gpt-4", input="Search for weather in NYC", tools=[{"type": "web_search"}],)# Automatically verified