Skip to main content
QWED Open Responses integrates with LangChain via a callback handler.

Installation


Quick start

LangChain 1.x create_agent has no callbacks argument, so pass the handler in config on each invoke() call. LangChain then reports every tool call to the handler before the tool runs. The handler checks it as {"type": "tool_call", "tool_name": <tool name>, "arguments": {"input": <tool input string>}}.

Configuration

QWEDCallbackHandler options


Example: blocking dangerous tools


Example: safety checks

QWEDCallbackHandler forwards verification_context only when a callback emitter explicitly supplies that keyword. The standard LangChain agent path does not supply it, so this handler cannot apply trusted total_cost or total_tokens across an agent run. Do not rely on this callback for run-wide max_cost or max_tokens enforcement. Leave both unset here: with no cost or token figure, the budget check fails closed, so a SafetyGuard with max_cost or max_tokens in this callback blocks every tool call. The LlamaIndex handler reads verification_context from the event keyword arguments or the event payload.

Handling blocked actions

A tool call blocked on the create_agent path carries the verification result in e.result. e.action is None there, because LangChain 1.x sends the tool start rather than an agent action.

Verification summary

The summary counts agent actions and agent finishes. LangChain 1.x create_agent reports tool calls only as tool starts, and in v0.6.1 tool-start checks are not added to the summary, so with create_agent it stays at zero. Use verbose=True or catch ToolCallBlocked to see each check.

Full example

Keep MathGuard out of this callback. It checks a response’s output, not tool-call arguments, so it fails every tool call with “No verifiable math found in response”. Check the agent’s final answer with MathGuard separately if it carries a calculation.