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:- Calculate: FV = P(1 + r/n)^(nt) = 10000(1 + 0.05/12)^(12×10)
- Call
execute_python_codeto verify:
Example 2: legal reasoning
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:- Formalize the logic
- Call
execute_python_codewith a Z3 solver script:
Example 3: secure code review
Scenario
A developer asks AI to review their code for security issues.Conversation
User: Review this login function:- Call
execute_python_codewith a CodeGuard analysis:
- SQL injection — direct string formatting in SQL query
- Code injection — using
eval()for password comparison
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: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:- Generate query
- Call
execute_python_codewith a SQLGuard check before responding:
Example 6: background verification
Scenario
You need to run a complex, multi-guard verification that may exceed the default 30-second timeout. Usebackground=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:- Call
execute_python_codewithbackground=true:
- Poll for results using
verification_status:
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
Setbackground=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:- Acknowledge the error
- Recalculate
- Verify again
- Explain the correction to user