Skip to main content
Real-world examples of using QWED Open Responses for agent verification.

Example 1: financial calculator agent

Scenario

An AI agent helps users with financial calculations. Need to verify math before returning results.

Setup

MathGuard checks total = subtotal + tax + shipping - discount, counting any missing part as zero. See what it checks for the other shapes.

Verification

Catching errors


Example 2: blocking dangerous tools

Scenario

Agent has access to shell commands. Need to prevent dangerous operations.

Setup

Blocked calls

Allowed calls


Example 3: PII detection

Scenario

Healthcare AI generating patient summaries. Must not leak PII.

Setup

PII blocked

A match on a custom_patterns entry is an error rather than a warning, so it blocks with any verifier:

Warn instead of block

SafetyGuard detects PII but does not redact it. Redact in your own code before you return the text.

Example 4: state machine validation

Scenario

Order processing agent. States must follow valid transitions.

Setup

StateGuard reads the requested state from new_state in the output. It does not read tool-call arguments, so pass the transition as structured output. Take the current state from your own records and pass it as context["current_state"]. That value wins over any state field in the output, so the agent can’t claim a different starting state to make a transition pass.

Valid transition

Invalid transition (blocked)


Example 5: LangChain integration

Full agent with verification

MathGuard is not in this callback. It checks a response’s output, not tool-call arguments, so it would block every tool call with “No verifiable math found in response”. See the LangChain integration for how the callback sees each tool call.

Example 6: budget control

Scenario

Prevent runaway API costs from agent loops.

Setup

SafetyGuard does not price calls. Keep your own running cost for the session and pass it as context["total_cost"] on each check. Any usage.cost the response reports is added to that total. With no cost figure at all, the budget check fails closed.

Budget enforcement


Example 7: argument type validation

Scenario

Ensure tool arguments match expected types.

Setup

Validation


Best practices

1. Layer multiple guards

Keep SchemaGuard and MathGuard in a separate stack from tool-call checks. A tool call does not match your output schema and carries no math, so both would fail it.

2. Fail fast, log everything

3. Environment-specific guards

4. Test your guards