Skip to main content

Example 1: financial calculations

Scenario

You’re building an LLM-backed financial advisor. Users ask for compound interest calculations, and you need QWED to verify the LLM’s math.

Setup

Conversation

User: Calculate the future value of $10,000 invested at 5% annual interest, compounded monthly, for 10 years. Claude’s process:
  1. Calculate: FV = P(1 + r/n)^(nt) = 10000(1 + 0.05/12)^(12×10)
  2. Call execute_python_code to verify:
Result:
Claude’s response: The future value is $16,470.09 (verified using deterministic decimal arithmetic).

Scenario

An AI legal assistant needs to verify that conclusions follow from legal premises.

Conversation

User: Under contract law: If both parties agree and consideration is exchanged, a contract is formed. Alice agreed and paid Bob. Is there a valid contract? Claude’s process:
  1. Formalize the logic
  2. Call execute_python_code with a Z3 solver script:
Result: Verified — the conclusion logically follows.

Example 3: secure code review

Scenario

A developer asks AI to review their code for security issues.

Conversation

User: Review this login function:
Claude’s process:
  1. Call execute_python_code with a CodeGuard analysis:
Result:
Claude’s response: Security issues found:
  1. SQL injection — direct string formatting in SQL query
  2. Code injection — using eval() for password comparison
Recommended fix:

Example 4: research paper validation

Scenario

Verifying statistical claims in AI-assisted research paper review.

Conversation

User: The paper claims: “If the p-value < 0.05, we reject the null hypothesis. Our p-value was 0.03. Therefore, we reject the null hypothesis.” Claude’s process:
Result: Verified.

Example 5: SQL query validation

Scenario

An AI data analyst generates SQL queries. You need to ensure they’re safe before execution.

Conversation

User: Get all orders for user input “admin’ OR ‘1’=‘1” Claude’s process:
  1. Generate query
  2. Call execute_python_code with a SQLGuard check before responding:
Result:
Claude’s response: The input appears to be a SQL injection attempt. Use parameterized queries:

Example 6: background verification

Scenario

You need to run a complex, multi-guard verification that may exceed the default 30-second timeout. Use background=true to dispatch the job asynchronously, then poll for results with verification_status.

Conversation

User: Run a full legal contract review including deadline, liability, and provenance checks on this 50-page NDA. Claude’s process:
  1. Call execute_python_code with background=true:
Response:
  1. Poll for results using verification_status:
Response:
Background jobs are ideal for multi-guard verification pipelines, large document analysis, or any script that may exceed the 30-second synchronous timeout.

Example 7: integration with LangChain

Python code


Best practices

1. Always verify before responding

2. Use background mode for heavy tasks

Set background=true when running scripts that may take longer than 30 seconds. Poll results using verification_status with the returned job_id.

3. Use appropriate SDK imports

4. Handle verification failures

When verification fails:
  1. Acknowledge the error
  2. Recalculate
  3. Verify again
  4. Explain the correction to user

5. Explain verification to users