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 check that a conclusion follows 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 argument as propositions
- Call
execute_python_codewith a script that looks for a truth assignment where the premises hold and the conclusion does not:
Example 3: code that is refused
Scenario
A script tries to reach the file system. The server refuses it before it runs.Conversation
User: Run this withexecute_python_code:
open, eval or getattr, or reads a private attribute is refused the same way, with the reason. Imports of QWED SDK packages, such as qwed_new or qwed_legal, and of other third-party packages are refused too. See What code is admitted.
Example 4: loan EMI
Scenario
A car dealer quotes a monthly instalment, and you want the assistant to check it.Conversation
User: A dealer claims: “₹10,00,000 loan at 9% annual interest for 5 years = EMI of ₹20,758”. Check it. Claude’s process:Example 5: background job
Scenario
You need to run a script that may exceed the 30-second synchronous timeout. Usebackground=true to dispatch the job asynchronously, then poll for results with verification_status.
Conversation
User: Sum 1/k² for k from 1 to 2,000,000 and compare it with π²/6. Claude’s process:- Call
execute_python_codewithbackground=true:
- Poll for results using
verification_status:
Background jobs suit any script that may exceed the 30-second synchronous timeout. They are bounded by
QWED_MCP_BACKGROUND_TIMEOUT (default 120 seconds, at most 600). See Execution limits.Example 6: Python MCP client
Python code
Start the server over stdio and call both tools from your own code with the MCP Python SDK. This example setsQWED_MCP_TRUSTED_CODE_EXECUTION for the server it starts.
qwed-mcp repository ships a fuller version of this client in its examples directory.
Math, logic and SQL engines
The math, logic and SQL engines inqwed_mcp.engines are a Python library API, not MCP tools, and execute_python_code scripts can’t import them. Call them from your own code, for example:
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 admitted modules
See What code is admitted for the full rules.
4. Handle verification failures
When verification fails:- Acknowledge the error
- Recalculate
- Verify again
- Explain the correction to user