Calling verify() with no guards configured fails closed. ResponseVerifier() without default_guards (or VerifiedOpenAI without guards) returns verified=False with the reason “No guards configured”, and blocks the response in strict mode. Earlier versions returned verified=True in this case. Constructing VerifiedOpenAI without guards also emits a UserWarning, because fail-closed verification would block every response. Always configure at least one guard.
Basic verification
from qwed_open_responses import ResponseVerifierfrom qwed_open_responses.guards import ToolGuard, MathGuard, SafetyGuardverifier = ResponseVerifier()# Verify a tool call before executionresult = verifier.verify_tool_call( tool_name="calculator", arguments={"operation": "multiply", "x": 150, "y": 10}, guards=[ToolGuard(), SafetyGuard()],)if result.verified: print("✅ Safe to execute")else: print(f"❌ Blocked: {result.block_reason}")# ✅ Safe to execute# Verify the math in the agent's answerresult = verifier.verify({"output": "150 * 10 = 1600"}, guards=[MathGuard()])print(result.verified, result.block_reason)# False Math verification failed: 1 error(s)print(result.guard_results[0].details["errors"])# ['Calculation error: 150.0 * 10.0 = 1600.0 (should be 1500.0)']
MathGuard checks the response’s output, such as the agent’s answer or a structured output. It does not read tool-call arguments, so a tool call on its own fails MathGuard with “No verifiable math found in response”.
verify_structured_output requires a schema or at least one guard. Calling it with neither raises ValueError, because the call would verify nothing. An explicitly supplied empty schema {} is honored as a valid JSON Schema that matches anything.
Framework integration
LangChain
from langchain_openai import ChatOpenAIfrom langchain.agents import create_agentfrom qwed_open_responses.guards import ToolGuard, SafetyGuardfrom qwed_open_responses.middleware.langchain import QWEDCallbackHandler# Create callback with guardscallback = QWEDCallbackHandler( guards=[ToolGuard(), SafetyGuard()], block_on_failure=True, # Stop execution if guard fails)# Create the agent, then pass the callback when you run itllm = ChatOpenAI(model="gpt-4")agent = create_agent(llm, tools=tools) # your tools# Every tool call is now verified before the tool runsresult = agent.invoke( {"messages": [{"role": "user", "content": "Calculate 25% of 500"}]}, config={"callbacks": [callback]},)
OpenAI SDK
from qwed_open_responses.middleware.openai_sdk import VerifiedOpenAIfrom qwed_open_responses.guards import ToolGuard, SafetyGuard# Create verified clientclient = VerifiedOpenAI( api_key="sk-...", guards=[ToolGuard(), SafetyGuard()],)# Use normally - verification is automaticresponse = client.chat.completions.create( model="gpt-4", messages=[{"role": "user", "content": "Generate an order"}], tools=my_tools,)# Tool calls are verified before returningfor tool_call in response.choices[0].message.tool_calls or []: print(f"Verified tool call: {tool_call.function.name}")
Keep SchemaGuard out of the client’s guards. It validates the whole response object rather than the model’s JSON, so every response fails. See structured outputs for checking the model’s JSON instead.
Streaming middleware
The OpenResponsesMiddleware intercepts streaming events from the Open Responses protocol, verifying tool_call and function_call items through your guard stack before they are yielded to the consumer.
Usage
from qwed_open_responses.middleware.streaming_interceptor import OpenResponsesMiddlewarefrom qwed_open_responses.guards import ToolGuard, SafetyGuardmiddleware = OpenResponsesMiddleware( guards=[ToolGuard(), SafetyGuard()], block_on_failure=True, # Replace blocked items with system_intervention on_blocked=my_callback, # Optional callback when an item is blocked)# Wrap any async stream of Open Responses itemsasync for item in middleware.verify_stream(response_stream): process(item)# Check runtime statsprint(middleware.get_stats())# {"total": 12, "verified": 10, "blocked": 2}
Parameters
Parameter
Type
Default
Description
guards
list[BaseGuard]
[]
Guards to run against each tool-call item
block_on_failure
bool
True
When True, blocked items are replaced with a system_intervention item. When False, blocked items pass through unmodified (warn-only)
on_blocked
callable
None
Optional callback invoked with (item, result) when a tool call is blocked
How it works
Non-tool items (text, metadata) pass through unchanged
Items with type of tool_call or function_call are verified against all guards in their original shape, before the middleware yields them. The type match ignores case and surrounding whitespace, so " Function_Call " is verified as a function_call
Tool-shaped items that can’t be verified unambiguously are blocked. This covers items with an unknown type, ambiguous envelopes, and tool calls nested inside other items
tool_result and function_call_output items pass through; the middleware does not validate their correlation metadata. Results that hide a nested tool call are blocked
If verification passes, the original item is yielded
If verification fails and block_on_failure is True, a system_intervention item is yielded instead:
ArgumentGuard and TaxGuard checks also run on batched and nested tool calls inside a streamed item, not only on the top-level call.
Budget tracking across a stream
Pass a context to verify_stream to enforce SafetyGuard budget limits for the whole stream:
middleware = OpenResponsesMiddleware( guards=[ToolGuard(), SafetyGuard(max_cost=5.0, max_tokens=20_000)],)async for item in middleware.verify_stream( response_stream, context={"total_cost": 1.25, "total_tokens": 4_000},): process(item)
The middleware copies the context and adds each item’s reported usage.cost and usage.total_tokens to the running total_cost and total_tokens. Later tool calls are verified against those totals, so a call that arrives after the budget is spent is blocked. Your original context dictionary is not modified.
{"docsConfig":{"theme":"aspen","$schema":"https://mintlify.com/docs.json","name":"QWED Documentation","description":"Official documentation for QWED. Learn deterministic verification for LLMs and AI agents using formal methods, symbolic execution, and policy guards.","colors":{"primary":"#B23E10","light":"#FF9A6B","dark":"#C8461A"},"logo":{"light":"https://mintcdn.com/qwed-ai/EsPQGLxTbf5KRu3h/images/brand/qwed-lockup.svg?fit=max\u0026auto=format\u0026n=EsPQGLxTbf5KRu3h\u0026q=85\u0026s=55ee43f7b81a257ed72eb042dd4a818c","dark":"https://mintcdn.com/qwed-ai/EsPQGLxTbf5KRu3h/images/brand/qwed-lockup-white.svg?fit=max\u0026auto=format\u0026n=EsPQGLxTbf5KRu3h\u0026q=85\u0026s=8d8398b35bf30dff8f5b930d6b0f204d","href":"https://docs.qwedai.tech"},"favicon":"https://mintcdn.com/qwed-ai/EsPQGLxTbf5KRu3h/images/brand/favicon.svg?fit=max\u0026auto=format\u0026n=EsPQGLxTbf5KRu3h\u0026q=85\u0026s=1aa3c9c1e9c63af145166f800c979b99","appearance":{"default":"system"},"background":{"color":{"light":"#F6F7F5","dark":"#0E1714"}},"navbar":{"links":[{"href":"https://qwedai.tech","label":"qwedai.tech"},{"href":"mailto:support@qwedai.tech","label":"Support"}],"primary":{"type":"button","label":"Get Started","href":"/getting-started/installation"}},"footer":{"socials":{"x":"https://x.com/Qwed_ai","github":"https://github.com/QWED-AI","linkedin":"https://www.linkedin.com/company/qwed","website":"https://qwedai.tech"},"links":[{"header":"SDKs","items":[{"label":"Python","href":"/sdks/python"},{"label":"Go","href":"/sdks/go"},{"label":"TypeScript","href":"/sdks/typescript"},{"label":"Rust","href":"/sdks/rust"}]},{"header":"Integration","items":[{"label":"CrewAI","href":"/integrations/crewai"},{"label":"LangChain","href":"/integrations/langchain"},{"label":"LlamaIndex","href":"/integrations/llamaindex"}]},{"header":"Ecosystem","items":[{"label":"QWED UCP","href":"/ucp/overview"},{"label":"QWED MCP","href":"/mcp/overview"},{"label":"Open Responses","href":"/open-responses/overview"},{"label":"QWED Finance","href":"https://finance.qwedai.tech"},{"label":"QWED Legal","href":"/legal/overview"},{"label":"QWED A2A","href":"/a2a/overview"},{"label":"QWED Learning","href":"https://github.com/QWED-AI/qwed-learning"}]},{"header":"Resources","items":[{"label":"Releases","href":"/releases"},{"label":"Changelog","href":"/changelog"},{"label":"License","href":"https://qwedai.tech/license"},{"label":"Privacy Policy","href":"https://qwedai.tech/privacy"},{"label":"Terms","href":"https://qwedai.tech/terms"}]}]},"seo":{"metatags":{"canonical":"https://docs.qwedai.tech","og:image":"https://docs.qwedai.tech/images/brand/og-docs.png","og:site_name":"QWED Documentation","og:type":"website","twitter:card":"summary_large_image"},"indexing":"all"},"fonts":{"heading":{"family":"Geist","weight":600},"body":{"family":"Geist"}},"banner":{"content":"**QWED v8.0.0** signs every verified answer, fixes six security advisories, and changes some SDK types and settings. [Upgrade guide](/changelog#v8-0-0-—-attested-verdicts-and-upgrade-guide)","dismissible":true},"styling":{"latex":true},"navigation":{"global":{"anchors":[{"anchor":"GitHub","icon":"github","href":"https://github.com/QWED-AI/qwed-verification/"},{"anchor":"Marketplace","icon":"shop","href":"https://github.com/marketplace/qwed-security"},{"anchor":"PyPI","icon":"python","href":"https://pypi.org/project/qwed/"},{"anchor":"Docker","icon":"docker","href":"https://hub.docker.com/orgs/qwedai/repositories"}]},"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"qwed-ai","hasAudioNarration":false,"actualSubdomain":"qwed-ai","customDomains":["docs.qwedai.tech"],"gitSource":{"type":"github","owner":"qwed-ai","repo":"docs","deployBranch":"main","contentDirectory":"","isPrivate":false,"mountPath":"","label":""},"feedback":{"edits":false},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6afc97ceeca6bf736113d5e4","clientVersion":"0.0.4177","searchFilterCounts":[{"language":"default","tag":"Reference","count":23},{"language":"default","tag":"Guides","count":22},{"language":"default","tag":"Protocols","count":16},{"language":"default","tag":"Engines","count":14},{"language":"default","tag":"SDKs \u0026 API","count":12},{"language":"default","tag":"Getting Started","count":12},{"language":"default","tag":"Extensions","count":12},{"language":"default","tag":"A2A Protocol","count":7},{"language":"default","tag":"Security \u0026 Compliance","count":7},{"language":"default","tag":"Concepts","count":7}],"searchSettings":{"isFiltersEnabled":true}},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":true,"enableContextualStarterQuestions":true,"enableAskAiSearchBar":true,"deflection":{"enabled":true,"email":"support@qwedai.com","showHelpButton":true}},"basePath":"","hasChatPermissions":true,"hasWebMcpPermissions":true,"toggles":[],"privacy":{"consentBanner":{"enabled":true}},"googleFontsInlined":true},"customCss":[{"filePath":"style.css","content":"/* cyrillic-ext */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 400 600;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrodmgPn.woff2) format('woff2');\n unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;\n}\n/* cyrillic */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 400 600;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrMdmgPn.woff2) format('woff2');\n unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;\n}\n/* symbols2 */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 400 600;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFg08vz7ehw.woff2) format('woff2');\n unicode-range: U+2000-2001, U+2004-2008, U+200A, U+23B8-23BD, U+2500-259F;\n}\n/* vietnamese */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 400 600;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrgdmgPn.woff2) format('woff2');\n unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;\n}\n/* latin-ext */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 400 600;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrkdmgPn.woff2) format('woff2');\n unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;\n}\n/* latin */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 400 600;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrcdmg.woff2) format('woff2');\n unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;\n}\ncode,pre,kbd,samp{font-family:'Geist Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace}#page-title,.mdx-content>h2{letter-spacing:-0.035em}.mdx-content>h3{letter-spacing:-0.01em}"}],"page":{"pagePath":"open-responses/overview","slug":"/open-responses/overview","pageMetadata":{"sidebar_position":1,"title":"QWED Open Responses: verified tool calls for AI agents","sidebarTitle":"Overview","description":"QWED Open Responses adds verified tool calls, deterministic guards, and AI agent security checks to OpenAI, LangChain, and LlamaIndex workflows.","href":"/open-responses/overview"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"QWED Open Responses adds verified tool calls, deterministic guards, and AI agent security checks to OpenAI, LangChain, and LlamaIndex workflows.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,hr:`hr`,img:`img`,li:`li`,ol:`ol`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Table,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Table)_missingMdxReference(`Table`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsx(_components.p,{children:_jsx(_components.strong,{children:`Verify AI agent outputs before execution.`})}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.a,{href:`https://pypi.org/project/qwed-open-responses/`,children:_jsx(_components.img,{src:`https://img.shields.io/pypi/v/qwed-open-responses`,alt:`PyPI version`})}),`\n`,_jsx(_components.a,{href:`https://github.com/QWED-AI/qwed-open-responses/actions`,children:_jsx(_components.img,{src:`https://github.com/QWED-AI/qwed-open-responses/actions/workflows/ci.yml/badge.svg`,alt:`Tests`})}),`\n`,_jsx(_components.a,{href:`https://opensource.org/licenses/Apache-2.0`,children:_jsx(_components.img,{src:`https://img.shields.io/badge/License-Apache%202.0-blue.svg`,alt:`License`})})]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`what-is-qwed-open-responses`,children:`What is QWED Open Responses?`}),`\n`,_jsxs(_components.p,{children:[`QWED Open Responses provides `,_jsx(_components.strong,{children:`deterministic verification guards`}),` for AI agent outputs. It works with:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`OpenAI Responses API`}),`\n`,_jsx(_components.li,{children:`LangChain agents`}),`\n`,_jsx(_components.li,{children:`LlamaIndex`}),`\n`,_jsx(_components.li,{children:`Any AI framework`}),`\n`]}),`\n`,_jsx(_components.p,{children:`Use it when you need runtime tool call verification, AI safety guardrails, and policy enforcement before an agent executes an action.`}),`\n`,_jsx(Heading,{level:`3`,id:`the-problem`,children:`The problem`}),`\n`,_jsx(_components.p,{children:`When AI agents execute tools or generate structured outputs, they can:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`🔧 `,_jsx(_components.strong,{children:`Call dangerous functions`}),` - `,_jsx(_components.code,{children:`rm -rf /`}),`, `,_jsx(_components.code,{children:`DROP TABLE`})]}),`\n`,_jsxs(_components.li,{children:[`🧮 `,_jsx(_components.strong,{children:`Produce incorrect calculations`}),` - Financial errors, wrong totals`]}),`\n`,_jsxs(_components.li,{children:[`📋 `,_jsx(_components.strong,{children:`Violate business rules`}),` - Invalid state transitions`]}),`\n`,_jsxs(_components.li,{children:[`🔐 `,_jsx(_components.strong,{children:`Leak sensitive data`}),` - PII, API keys in responses`]}),`\n`,_jsxs(_components.li,{children:[`💰 `,_jsx(_components.strong,{children:`Exceed budgets`}),` - Unlimited API calls`]}),`\n`]}),`\n`,_jsx(Heading,{level:`3`,id:`the-solution`,children:`The solution`}),`\n`,_jsx(_components.p,{children:`QWED Open Responses intercepts and verifies every agent output before execution:`}),`\n`,_jsx(CodeBlock,{numberOfLines:`5`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`5`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`AI Agent Output → Guards → Verified? → Execute`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` │`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` YES ───┘`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` NO ────→ Block + Error`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`how-it-works`,children:`How it works`}),`\n`,_jsx(CodeBlock,{numberOfLines:`32`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`32`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`┌─────────────────────────────────────────────────────────────────┐`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`│ AI Agent (GPT, Claude, etc.) │`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`│ │`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`│ \"Call calculator with x=150, y=10, result=1600\" │`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`└──────────────────────────┬───────────────────────────────────────┘`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` │`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` │ Tool Call / Structured Output`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` ▼`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`┌─────────────────────────────────────────────────────────────────┐`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`│ QWED Open Responses Verifier │`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`├─────────────────────────────────────────────────────────────────┤`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`│ │`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`│ ┌─────────────┐ ┌─────────────┐ ┌───────────────────────────┐│`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`│ │ SchemaGuard │ │ ToolGuard │ │ MathGuard ││`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`│ │ JSON Valid │ │ Blocklist │ │ 150 × 10 ≠ 1600 ❌ ││`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`│ └─────────────┘ └─────────────┘ └───────────────────────────┘│`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`│ │`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`│ ┌─────────────┐ ┌─────────────┐ ┌───────────────────────────┐│`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`│ │ StateGuard │ │ArgumentGuard│ │ SafetyGuard ││`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`│ │ Transitions │ │ Type Check │ │ PII, Injection, Budget ││`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`│ └─────────────┘ └─────────────┘ └───────────────────────────┘│`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`│ │`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`│ MathGuard Failed: 150 × 10 = 1500, not 1600 │`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`│ │`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`└──────────────────────────┬───────────────────────────────────────┘`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` │`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` ▼`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` ┌─────────────────┐`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` │ ❌ BLOCKED │`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` │ Return error │`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` └─────────────────┘`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`the-6-guards`,children:`The 6 guards`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Guard`}),_jsx(_components.th,{children:`What it verifies`}),_jsx(_components.th,{children:`Example catch`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`SchemaGuard`})}),_jsx(_components.td,{children:`JSON Schema compliance`}),_jsx(_components.td,{children:`Missing required field`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`ToolGuard`})}),_jsx(_components.td,{children:`Block dangerous tool calls`}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`execute_shell`}),` blocked`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`MathGuard`})}),_jsx(_components.td,{children:`Verify calculations`}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`150 × 10 ≠ 1600`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`StateGuard`})}),_jsx(_components.td,{children:`Valid state transitions`}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`completed → pending`}),` invalid`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`ArgumentGuard`})}),_jsx(_components.td,{children:`Tool argument validation`}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`amount: \"abc\"`}),` not a number`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`SafetyGuard`})}),_jsx(_components.td,{children:`PII, injection, budget`}),_jsx(_components.td,{children:`SSN detected in output`})]})]})]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`installation`,children:`Installation`}),`\n`,_jsx(Heading,{level:`3`,id:`basic`,children:`Basic`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`pip`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` install qwed-open-responses`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`with-framework-integrations`,children:`With framework integrations`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`8`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`8`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# OpenAI`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`pip`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` install qwed-open-responses[openai]`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# LangChain`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`pip`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` install qwed-open-responses[langchain]`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# All integrations`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`pip`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` install qwed-open-responses[all]`})]}),`\n`]})})}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`quick-start`,children:`Quick start`}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`Calling `,_jsx(_components.code,{children:`verify()`}),` with no guards configured fails closed. `,_jsx(_components.code,{children:`ResponseVerifier()`}),` without `,_jsx(_components.code,{children:`default_guards`}),` (or `,_jsx(_components.code,{children:`VerifiedOpenAI`}),` without `,_jsx(_components.code,{children:`guards`}),`) returns `,_jsx(_components.code,{children:`verified=False`}),` with the reason “No guards configured”, and blocks the response in strict mode. Earlier versions returned `,_jsx(_components.code,{children:`verified=True`}),` in this case. Constructing `,_jsx(_components.code,{children:`VerifiedOpenAI`}),` without guards also emits a `,_jsx(_components.code,{children:`UserWarning`}),`, because fail-closed verification would block every response. Always configure at least one guard.`]})}),`\n`,_jsx(Heading,{level:`3`,id:`basic-verification`,children:`Basic verification`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`24`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`24`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` qwed_open_responses `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ResponseVerifier`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` qwed_open_responses.guards `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ToolGuard, MathGuard, SafetyGuard`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`verifier = ResponseVerifier()`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Verify a tool call before execution`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`result = verifier.verify_tool_call(`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tool_name=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"calculator\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` arguments={`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"operation\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"multiply\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"x\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: 150, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"y\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: 10},`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` guards=[ToolGuard(), SafetyGuard()],`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` result.verified:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` print(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"✅ Safe to execute\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`else`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` print(f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"❌ Blocked: {result.block_reason}\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# ✅ Safe to execute`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Verify the math in the agent's answer`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`result = verifier.verify({`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"output\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"150 * 10 = 1600\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}, guards=[MathGuard()])`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`print(result.verified, result.block_reason)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# False Math verification failed: 1 error(s)`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`print(result.guard_results[0].details[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"errors\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`])`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# ['Calculation error: 150.0 * 10.0 = 1600.0 (should be 1500.0)']`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`MathGuard checks the response’s `,_jsx(_components.code,{children:`output`}),`, such as the agent’s answer or a structured output. It does not read tool-call arguments, so a tool call on its own fails MathGuard with “No verifiable math found in response”.`]}),`\n`,_jsx(Heading,{level:`3`,id:`verify-structured-output`,children:`Verify structured output`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`21`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`21`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` qwed_open_responses.guards `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` SchemaGuard`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Define expected schema`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`order_schema = {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"object\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"required\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"order_id\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"total\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"items\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"properties\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"order_id\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"string\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`},`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"total\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"number\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"minimum\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: 0},`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"items\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"array\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"minItems\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: 1}`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`result = verifier.verify_structured_output(`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` output={`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"order_id\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"ORD-123\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"total\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: 99.99,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"items\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"name\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Widget\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"price\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: 99.99}]`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` guards=[SchemaGuard(schema=order_schema)]`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`verify_structured_output`}),` requires a `,_jsx(_components.code,{children:`schema`}),` or at least one guard. Calling it with neither raises `,_jsx(_components.code,{children:`ValueError`}),`, because the call would verify nothing. An explicitly supplied empty schema `,_jsx(_components.code,{children:`{}`}),` is honored as a valid JSON Schema that matches anything.`]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`framework-integration`,children:`Framework integration`}),`\n`,_jsx(Heading,{level:`3`,id:`langchain`,children:`LangChain`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`20`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`20`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langchain_openai `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ChatOpenAI`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langchain.agents `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` create_agent`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` qwed_open_responses.guards `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ToolGuard, SafetyGuard`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` qwed_open_responses.middleware.langchain `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` QWEDCallbackHandler`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Create callback with guards`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`callback = QWEDCallbackHandler(`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` guards=[ToolGuard(), SafetyGuard()],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block_on_failure=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Stop execution if guard fails`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Create the agent, then pass the callback when you run it`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`llm = ChatOpenAI(model=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"gpt-4\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`agent = create_agent(llm, tools=tools) `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# your tools`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Every tool call is now verified before the tool runs`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`result = agent.invoke(`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"messages\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Calculate 25% of 500\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}]},`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` config={`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"callbacks\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [callback]},`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`openai-sdk`,children:`OpenAI SDK`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`19`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`19`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` qwed_open_responses.middleware.openai_sdk `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` VerifiedOpenAI`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` qwed_open_responses.guards `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ToolGuard, SafetyGuard`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Create verified client`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`client = VerifiedOpenAI(`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` api_key=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"sk-...\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` guards=[ToolGuard(), SafetyGuard()],`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Use normally - verification is automatic`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`response = client.chat.completions.create(`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` model=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"gpt-4\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` messages=[{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Generate an order\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}],`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tools=my_tools,`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Tool calls are verified before returning`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tool_call `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response.choices[0].message.tool_calls `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`or`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` []:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` print(f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Verified tool call: {tool_call.function.name}\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Keep `,_jsx(_components.code,{children:`SchemaGuard`}),` out of the client’s guards. It validates the whole response object rather than the model’s JSON, so every response fails. See `,_jsx(_components.a,{href:`/open-responses/openai#structured-outputs`,children:`structured outputs`}),` for checking the model’s JSON instead.`]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`streaming-middleware`,children:`Streaming middleware`}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`OpenResponsesMiddleware`}),` intercepts streaming events from the Open Responses protocol, verifying `,_jsx(_components.code,{children:`tool_call`}),` and `,_jsx(_components.code,{children:`function_call`}),` items through your guard stack before they are yielded to the consumer.`]}),`\n`,_jsx(Heading,{level:`3`,id:`usage`,children:`Usage`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`16`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`16`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` qwed_open_responses.middleware.streaming_interceptor `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` OpenResponsesMiddleware`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` qwed_open_responses.guards `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ToolGuard, SafetyGuard`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`middleware = OpenResponsesMiddleware(`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` guards=[ToolGuard(), SafetyGuard()],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block_on_failure=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Replace blocked items with system_intervention`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` on_blocked=my_callback, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Optional callback when an item is blocked`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Wrap any async stream of Open Responses items`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`async`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` item `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` middleware.verify_stream(response_stream):`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` process(item)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Check runtime stats`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`print(middleware.get_stats())`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# {\"total\": 12, \"verified\": 10, \"blocked\": 2}`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`parameters`,children:`Parameters`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Parameter`}),_jsx(_components.th,{children:`Type`}),_jsx(_components.th,{children:`Default`}),_jsx(_components.th,{children:`Description`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`guards`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`list[BaseGuard]`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`[]`})}),_jsx(_components.td,{children:`Guards to run against each tool-call item`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`block_on_failure`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`bool`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`True`})}),_jsxs(_components.td,{children:[`When `,_jsx(_components.code,{children:`True`}),`, blocked items are replaced with a `,_jsx(_components.code,{children:`system_intervention`}),` item. When `,_jsx(_components.code,{children:`False`}),`, blocked items pass through unmodified (warn-only)`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`on_blocked`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`callable`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`None`})}),_jsxs(_components.td,{children:[`Optional callback invoked with `,_jsx(_components.code,{children:`(item, result)`}),` when a tool call is blocked`]})]})]})]}),`\n`,_jsx(Heading,{level:`3`,id:`how-it-works-2`,children:`How it works`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsx(_components.li,{children:`Non-tool items (text, metadata) pass through unchanged`}),`\n`,_jsxs(_components.li,{children:[`Items with `,_jsx(_components.code,{children:`type`}),` of `,_jsx(_components.code,{children:`tool_call`}),` or `,_jsx(_components.code,{children:`function_call`}),` are verified against all guards in their original shape, before the middleware yields them. The `,_jsx(_components.code,{children:`type`}),` match ignores case and surrounding whitespace, so `,_jsx(_components.code,{children:`\" Function_Call \"`}),` is verified as a `,_jsx(_components.code,{children:`function_call`})]}),`\n`,_jsxs(_components.li,{children:[`Tool-shaped items that can’t be verified unambiguously are blocked. This covers items with an unknown `,_jsx(_components.code,{children:`type`}),`, ambiguous envelopes, and tool calls nested inside other items`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`tool_result`}),` and `,_jsx(_components.code,{children:`function_call_output`}),` items pass through; the middleware does not validate their correlation metadata. Results that hide a nested tool call are blocked`]}),`\n`,_jsx(_components.li,{children:`If verification passes, the original item is yielded`}),`\n`,_jsxs(_components.li,{children:[`If verification fails and `,_jsx(_components.code,{children:`block_on_failure`}),` is `,_jsx(_components.code,{children:`True`}),`, a `,_jsx(_components.code,{children:`system_intervention`}),` item is yielded instead:`]}),`\n`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`11`,language:`json`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`json`,children:_jsxs(_components.code,{language:`json`,numberOfLines:`11`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"system_intervention\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"status\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"blocked\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"tool_name\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"execute_shell\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"reason\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"QWED blocked execute_shell: dangerous tool call\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"verification\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"guards_passed\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"SafetyGuard\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"guards_failed\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"ToolGuard\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"mechanism\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"QWED Open Responses Streaming Interceptor\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`ArgumentGuard and TaxGuard checks also run on batched and nested tool calls inside a streamed item, not only on the top-level call.`}),`\n`,_jsx(Heading,{level:`3`,id:`budget-tracking-across-a-stream`,children:`Budget tracking across a stream`}),`\n`,_jsxs(_components.p,{children:[`Pass a `,_jsx(_components.code,{children:`context`}),` to `,_jsx(_components.code,{children:`verify_stream`}),` to enforce SafetyGuard budget limits for the whole stream:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`9`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`9`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`middleware = OpenResponsesMiddleware(`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` guards=[ToolGuard(), SafetyGuard(max_cost=5.0, max_tokens=20_000)],`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`async`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` item `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` middleware.verify_stream(`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response_stream,`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` context={`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"total_cost\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: 1.25, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"total_tokens\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: 4_000},`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` process(item)`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`The middleware copies the context and adds each item’s reported `,_jsx(_components.code,{children:`usage.cost`}),` and `,_jsx(_components.code,{children:`usage.total_tokens`}),` to the running `,_jsx(_components.code,{children:`total_cost`}),` and `,_jsx(_components.code,{children:`total_tokens`}),`. Later tool calls are verified against those totals, so a call that arrives after the budget is spent is blocked. Your original context dictionary is not modified.`]}),`\n`,_jsx(Heading,{level:`3`,id:`stats-methods`,children:`Stats methods`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Method`}),_jsx(_components.th,{children:`Description`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`get_stats()`})}),_jsxs(_components.td,{children:[`Returns `,_jsx(_components.code,{children:`{\"total\": int, \"verified\": int, \"blocked\": int}`})]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`reset_stats()`})}),_jsx(_components.td,{children:`Resets all counters to zero`})]})]})]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`why-qwed-open-responses`,children:`Why QWED Open Responses?`}),`\n`,_jsx(Heading,{level:`3`,id:`security-comparison`,children:`Security comparison`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Threat`}),_jsx(_components.th,{children:`Without Verification`}),_jsx(_components.th,{children:`With QWED`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsxs(_components.td,{children:[`Agent calls `,_jsx(_components.code,{children:`rm -rf /`})]}),_jsx(_components.td,{children:`💀 System destroyed`}),_jsxs(_components.td,{children:[`✅ `,_jsx(_components.strong,{children:`BLOCKED`})]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`SQL injection in query`}),_jsx(_components.td,{children:`💀 Data breach`}),_jsxs(_components.td,{children:[`✅ `,_jsx(_components.strong,{children:`BLOCKED`})]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Wrong calculation`}),_jsx(_components.td,{children:`💸 Financial loss`}),_jsxs(_components.td,{children:[`✅ `,_jsx(_components.strong,{children:`CAUGHT`})]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`PII in API response`}),_jsx(_components.td,{children:`📋 Compliance violation`}),_jsxs(_components.td,{children:[`✅ `,_jsx(_components.strong,{children:`DETECTED`})]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Infinite tool loop`}),_jsx(_components.td,{children:`💰 $10,000 API bill`}),_jsxs(_components.td,{children:[`✅ `,_jsx(_components.strong,{children:`BUDGET GUARD`})]})]})]})]}),`\n`,_jsx(Heading,{level:`3`,id:`real-world-impact`,children:`Real-world impact`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Finance:`}),` Prevent wrong calculations in trading bots`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Healthcare:`}),` Block PII leaks in patient summaries`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`E-commerce:`}),` Verify order totals before payment`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`DevOps:`}),` Prevent dangerous shell commands`]}),`\n`]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`configuration`,children:`Configuration`}),`\n`,_jsx(Heading,{level:`3`,id:`environment-variables`,children:`Environment variables`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Variable`}),_jsx(_components.th,{children:`Description`}),_jsx(_components.th,{children:`Default`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`QWED_OR_LOG_LEVEL`})}),_jsx(_components.td,{children:`Logging level`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`INFO`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`QWED_OR_STRICT`})}),_jsx(_components.td,{children:`Fail on any guard failure`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`true`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`QWED_OR_MAX_BUDGET`})}),_jsx(_components.td,{children:`Maximum API cost allowed`}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`100.0`})})]})]})]}),`\n`,_jsx(Heading,{level:`3`,id:`custom-guard-configuration`,children:`Custom guard configuration`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`26`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`26`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` qwed_open_responses `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ResponseVerifier`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` qwed_open_responses.guards `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ToolGuard, SafetyGuard`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Custom tool blocklist, added to the default one`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`tool_guard = ToolGuard(`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` blocked_tools=[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"execute_shell\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"delete_database\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"send_email\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` allowed_tools=[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"search\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"calculator\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`], `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Block tools not on this list`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Custom safety settings`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`safety_guard = SafetyGuard(`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` check_pii=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` check_injection=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` max_cost=50.0, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# $50 limit, checked against context[\"total_cost\"]`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` custom_patterns=[r`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"password\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, r`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"secret\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, r`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"token\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`verifier = ResponseVerifier(default_guards=[tool_guard, safety_guard])`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`result = verifier.verify_tool_call(`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"search\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"query\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"weather\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`},`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` context={`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"total_cost\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: 4.20}, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# your running cost for this session`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`print(result.verified)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# True`})}),`\n`]})})}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`next-steps`,children:`Next steps`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.a,{href:`/open-responses/guards`,children:`Guards reference`}),` - Deep dive into each guard`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.a,{href:`/open-responses/examples`,children:`Examples`}),` - Real-world use cases`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.a,{href:`/open-responses/langchain`,children:`LangChain integration`}),` - Agent verification`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.a,{href:`/open-responses/openai`,children:`OpenAI integration`}),` - Responses API`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.a,{href:`/open-responses/troubleshooting`,children:`Troubleshooting`}),` - Common issues`]}),`\n`]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`links`,children:`Links`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`GitHub:`}),` `,_jsx(_components.a,{href:`https://github.com/QWED-AI/qwed-open-responses`,children:`QWED-AI/qwed-open-responses`})]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`PyPI:`}),` `,_jsx(_components.a,{href:`https://pypi.org/project/qwed-open-responses/`,children:`qwed-open-responses`})]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`npm:`}),` `,_jsx(_components.a,{href:`https://www.npmjs.com/package/qwed-open-responses`,children:`qwed-open-responses`})]}),`\n`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"sidebar_position":1,"title":"QWED Open Responses: verified tool calls for AI agents","sidebarTitle":"Overview","description":"QWED Open Responses adds verified tool calls, deterministic guards, and AI agent security checks to OpenAI, LangChain, and LlamaIndex workflows.","href":"/open-responses/overview"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"What is QWED Open Responses?","slug":"what-is-qwed-open-responses","depth":2,"children":[{"title":"The problem","slug":"the-problem","depth":3,"children":[]},{"title":"The solution","slug":"the-solution","depth":3,"children":[]}]},{"title":"How it works","slug":"how-it-works","depth":2,"children":[]},{"title":"The 6 guards","slug":"the-6-guards","depth":2,"children":[]},{"title":"Installation","slug":"installation","depth":2,"children":[{"title":"Basic","slug":"basic","depth":3,"children":[]},{"title":"With framework integrations","slug":"with-framework-integrations","depth":3,"children":[]}]},{"title":"Quick start","slug":"quick-start","depth":2,"children":[{"title":"Basic verification","slug":"basic-verification","depth":3,"children":[]},{"title":"Verify structured output","slug":"verify-structured-output","depth":3,"children":[]}]},{"title":"Framework integration","slug":"framework-integration","depth":2,"children":[{"title":"LangChain","slug":"langchain","depth":3,"children":[]},{"title":"OpenAI SDK","slug":"openai-sdk","depth":3,"children":[]}]},{"title":"Streaming middleware","slug":"streaming-middleware","depth":2,"children":[{"title":"Usage","slug":"usage","depth":3,"children":[]},{"title":"Parameters","slug":"parameters","depth":3,"children":[]},{"title":"How it works","slug":"how-it-works-2","depth":3,"children":[]},{"title":"Budget tracking across a stream","slug":"budget-tracking-across-a-stream","depth":3,"children":[]},{"title":"Stats methods","slug":"stats-methods","depth":3,"children":[]}]},{"title":"Why QWED Open Responses?","slug":"why-qwed-open-responses","depth":2,"children":[{"title":"Security comparison","slug":"security-comparison","depth":3,"children":[]},{"title":"Real-world impact","slug":"real-world-impact","depth":3,"children":[]}]},{"title":"Configuration","slug":"configuration","depth":2,"children":[{"title":"Environment variables","slug":"environment-variables","depth":3,"children":[]},{"title":"Custom guard configuration","slug":"custom-guard-configuration","depth":3,"children":[]}]},{"title":"Next steps","slug":"next-steps","depth":2,"children":[]},{"title":"Links","slug":"links","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"qwed-ai","siteName":"QWED Documentation","title":"QWED Open Responses: verified tool calls for AI agents - QWED Documentation","relatedPagesConfig":{"enabled":true,"limit":5,"mode":"automatic"},"contextualStarterQuestions":[{"_id":"6af71c432d431453c4d7a765","deploymentId":"6987dbb63e86850b547ce918","questionText":"Which AI frameworks are supported?","status":"active","generatedBy":"contextual","path":"open-responses/overview","createdAt":"2026-11-13T14:18:43.468Z","updatedAt":"2026-11-13T14:18:43.468Z","__v":0},{"_id":"6af71c432d431453c4d7a763","deploymentId":"6987dbb63e86850b547ce918","questionText":"How do I verify tool calls?","status":"active","generatedBy":"contextual","path":"open-responses/overview","createdAt":"2026-11-13T14:18:43.468Z","updatedAt":"2026-11-13T14:18:43.468Z","__v":0},{"_id":"6af71c432d431453c4d7a764","deploymentId":"6987dbb63e86850b547ce918","questionText":"What safety issues does it prevent?","status":"active","generatedBy":"contextual","path":"open-responses/overview","createdAt":"2026-11-13T14:18:43.468Z","updatedAt":"2026-11-13T14:18:43.468Z","__v":0}],"navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-11-13T14:18:40.965Z","originalFileLocation":"open-responses/overview.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"QWED Open Responses adds verified tool calls, deterministic guards, and AI agent security checks to OpenAI, LangChain, and LlamaIndex workflows.\">\u003cmeta data-mint-head name=\"application-name\" content=\"QWED Documentation\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/qwed-ai/BkCqUkT_Xz5RMHOK/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/qwed-ai/BkCqUkT_Xz5RMHOK/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/qwed-ai/BkCqUkT_Xz5RMHOK/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/qwed-ai/BkCqUkT_Xz5RMHOK/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/qwed-ai/BkCqUkT_Xz5RMHOK/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/qwed-ai/BkCqUkT_Xz5RMHOK/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/qwed-ai/BkCqUkT_Xz5RMHOK/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/qwed-ai/BkCqUkT_Xz5RMHOK/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/qwed-ai/BkCqUkT_Xz5RMHOK/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"QWED Open Responses: verified tool calls for AI agents - QWED Documentation\">\u003cmeta data-mint-head property=\"og:description\" content=\"QWED Open Responses adds verified tool calls, deterministic guards, and AI agent security checks to OpenAI, LangChain, and LlamaIndex workflows.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"QWED Documentation\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.qwedai.tech/open-responses/overview\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://docs.qwedai.tech/images/brand/og-docs.png\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"QWED Open Responses: verified tool calls for AI agents - QWED Documentation\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"QWED Open Responses adds verified tool calls, deterministic guards, and AI agent security checks to OpenAI, LangChain, and LlamaIndex workflows.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://docs.qwedai.tech/images/brand/og-docs.png\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/qwed-ai/BkCqUkT_Xz5RMHOK/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"QWED Documentation\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#B23E10\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.qwedai.tech/open-responses/overview\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/open-responses/overview.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.qwedai.tech/#organization\",\"name\":\"QWED Documentation\",\"url\":\"https://docs.qwedai.tech\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/qwed-ai/EsPQGLxTbf5KRu3h/images/brand/qwed-lockup.svg?fit=max\u0026auto=format\u0026n=EsPQGLxTbf5KRu3h\u0026q=85\u0026s=55ee43f7b81a257ed72eb042dd4a818c\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.qwedai.tech#website\",\"name\":\"QWED Documentation\",\"url\":\"https://docs.qwedai.tech\",\"publisher\":{\"@id\":\"https://docs.qwedai.tech/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.qwedai.tech/open-responses/overview#webpage\",\"url\":\"https://docs.qwedai.tech/open-responses/overview\",\"name\":\"QWED Open Responses: verified tool calls for AI agents\",\"description\":\"QWED Open Responses adds verified tool calls, deterministic guards, and AI agent security checks to OpenAI, LangChain, and LlamaIndex workflows.\",\"dateModified\":\"2026-11-13T14:18:40.965Z\",\"isPartOf\":{\"@id\":\"https://docs.qwedai.tech#website\"},\"breadcrumb\":{\"@id\":\"https://docs.qwedai.tech/open-responses/overview#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.qwedai.tech/open-responses/overview#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"QWED Documentation\",\"item\":\"https://docs.qwedai.tech\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"QWED Open Responses: verified tool calls for AI agents\",\"item\":\"https://docs.qwedai.tech/open-responses/overview\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.qwedai.tech/open-responses/overview#article\",\"headline\":\"QWED Open Responses: verified tool calls for AI agents\",\"name\":\"QWED Open Responses: verified tool calls for AI agents\",\"description\":\"QWED Open Responses adds verified tool calls, deterministic guards, and AI agent security checks to OpenAI, LangChain, and LlamaIndex workflows.\",\"url\":\"https://docs.qwedai.tech/open-responses/overview\",\"mainEntityOfPage\":{\"@id\":\"https://docs.qwedai.tech/open-responses/overview#webpage\"},\"image\":\"https://docs.qwedai.tech/images/brand/og-docs.png\",\"dateModified\":\"2026-11-13T14:18:40.965Z\",\"publisher\":{\"@id\":\"https://docs.qwedai.tech/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.qwedai.tech#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"QWED Documentation\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"QWED Documentation\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/open-responses/overview.md","siteName":"QWED Documentation","nav":{"global":{"anchors":[{"anchor":"GitHub","icon":"github","href":"https://github.com/QWED-AI/qwed-verification/"},{"anchor":"Marketplace","icon":"shop","href":"https://github.com/marketplace/qwed-security"},{"anchor":"PyPI","icon":"python","href":"https://pypi.org/project/qwed/"},{"anchor":"Docker","icon":"docker","href":"https://hub.docker.com/orgs/qwedai/repositories"}]},"tabs":[{"tab":"Getting Started","pages":[{"title":"Getting Started","href":"/intro"}]},{"tab":"Engines","pages":[{"title":"Engines","href":"/engines/overview"}]},{"tab":"Extensions","pages":[{"title":"Extensions","href":"/finance/overview"}]},{"tab":"Protocols","groups":[{"group":"MCP Server","pages":[{"title":"QWED MCP: verification for Model Context Protocol","sidebarTitle":"MCP overview","href":"/mcp/overview"},{"title":"MCP tools reference","href":"/mcp/tools"},{"title":"QWED MCP examples for verified tool execution","sidebarTitle":"Examples and tutorials","href":"/mcp/examples"},{"title":"QWED MCP troubleshooting","sidebarTitle":"Troubleshooting","description":"Troubleshoot QWED MCP issues including installation problems, configuration errors, tool execution failures, and migration to execute_python_code.","href":"/mcp/troubleshooting"}]},{"group":"Open Responses","pages":[{"title":"QWED Open Responses: verified tool calls for AI agents","sidebarTitle":"Overview","href":"/open-responses/overview"},{"title":"QWED Open Responses guards for verified AI agents","sidebarTitle":"Guards reference","description":"Reference for QWED Open Responses guards including SchemaGuard and ToolGuard, with configuration options, error semantics, and tool-call validation examples.","href":"/open-responses/guards"},{"title":"OpenAI integration for verified AI agents","sidebarTitle":"OpenAI integration","href":"/open-responses/openai"},{"title":"LangChain integration for verified AI agents","sidebarTitle":"LangChain integration","href":"/open-responses/langchain"},{"title":"QWED Open Responses examples for verified AI agents","sidebarTitle":"Examples and use cases","href":"/open-responses/examples"},{"title":"QWED Open Responses troubleshooting","sidebarTitle":"Troubleshooting","href":"/open-responses/troubleshooting"}]},{"group":"UCP (Commerce)","pages":[{"title":"QWED UCP: transaction verification for AI commerce","sidebarTitle":"Overview","href":"/ucp/overview"},{"title":"QWED UCP guards for AI commerce verification","sidebarTitle":"Guards reference","href":"/ucp/guards"},{"title":"FastAPI middleware","href":"/ucp/middleware-fastapi"},{"title":"Express.js middleware","href":"/ucp/middleware-express"},{"title":"QWED UCP examples for AI commerce verification","sidebarTitle":"Examples and use cases","href":"/ucp/examples"},{"title":"QWED UCP troubleshooting","sidebarTitle":"Troubleshooting","href":"/ucp/troubleshooting"}]}]},{"tab":"A2A Protocol","pages":[{"title":"A2A Protocol","href":"/a2a/overview"}]},{"tab":"Integrations","pages":[{"title":"Integrations","href":"/integrations/langchain"}]},{"tab":"SDKs \u0026 API","pages":[{"title":"SDKs \u0026 API","href":"/api/overview"}]},{"tab":"Guides","pages":[{"title":"Guides","href":"/integration/getting-started"}]},{"tab":"Reference","pages":[{"title":"Reference","href":"/advanced/architecture-diagrams"}]}]},"basePath":"","title":"QWED Open Responses: verified tool calls for AI agents - QWED Documentation","deploymentId":"dpl_HhUetB7eHHDAmK9T1Teip38TgFx9","buildId":"dpl_HhUetB7eHHDAmK9T1Teip38TgFx9","dynamics":["10e4515597","a74be98ba7"],"chunks":["BannerMarkdown-BjdIPj1P.js","dist-C5gjFYHe.js","lib-DuNMoZ05.js","lib-B8HbPgcC.js","katex-YMM-FMeD.js","html-void-elements-mCSPHezU.js","marked.esm-CZWythHk.js","zoom-image-lightbox-DQG3o8Eu.js","lightbox-handle-r17bVUz3.js"]}