> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qwedai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Python SDK

> QWED Python SDK documentation. Install via pip, configure sync or async clients, and verify LLM outputs with math, logic, code, and SQL engines.

The official Python SDK for QWED.

## Installation

```bash theme={null}
pip install qwed
```

## Quick start

```python theme={null}
from qwed_sdk import QWEDClient

client = QWEDClient(api_key="qwed_your_key")

# Basic verification
result = client.verify("Is 2+2=4?")
print(result.verified)  # True
print(result.status)    # "VERIFIED"
```

<Note>
  As of v5.0.0, the `status` field may return `INCONCLUSIVE`, `BLOCKED`, or `UNKNOWN` in addition to `VERIFIED` and `ERROR`. Natural-language math queries return `INCONCLUSIVE` when the inner engine succeeds, because the LLM translation step is non-deterministic. See the [trust boundary documentation](/api/endpoints#post-verifynatural_language) for details.
</Note>

## Async client

```python theme={null}
from qwed_sdk import QWEDAsyncClient
import asyncio

async def main():
    async with QWEDAsyncClient(api_key="qwed_...") as client:
        result = await client.verify("2+2=4")
        print(result.verified)

asyncio.run(main())
```

## Methods

### verify(query)

Auto-detect and verify any claim.

```python theme={null}
result = client.verify("What is 15% of 200?")
```

### verify\_math(expression)

Verify mathematical expressions.

```python theme={null}
result = client.verify_math("x**2 + 2*x + 1 = (x+1)**2")
```

### verify\_logic(query)

Verify logical constraints (QWED-Logic DSL).

```python theme={null}
result = client.verify_logic("(AND (GT x 5) (LT y 10))")
print(result.model)  # {"x": 6, "y": 9}
```

### verify\_code(code, language)

Check code for security vulnerabilities.

```python theme={null}
result = client.verify_code(code, language="python")
for vuln in result.vulnerabilities:
    print(f"{vuln.severity}: {vuln.message}")
```

### verify\_sql(query, schema\_ddl, dialect)

Validate SQL queries against a schema.

```python theme={null}
result = client.verify_sql(
    query="SELECT * FROM users WHERE id = 1",
    schema_ddl="CREATE TABLE users (id INT, name TEXT)",
    dialect="postgresql"
)
```

### verify\_fact(claim, context)

<Info>New in v4.0.0</Info>

Verify factual claims against a provided context. Includes client-side PII pre-check.

```python theme={null}
result = client.verify_fact(
    claim="The company was founded in 2020",
    context="Acme Corp was established in 2020 in San Francisco."
)
print(result.verified)  # True
```

### verify\_stats(query, file\_path)

<Info>New in v4.0.0</Info>

Verify statistical claims against CSV data.

```python theme={null}
result = client.verify_stats(
    query="The average salary is above 50000",
    file_path="data.csv"
)
```

### verify\_consensus(query, mode, min\_confidence)

<Info>New in v4.0.0</Info>

Multi-engine consensus verification.

```python theme={null}
result = client.verify_consensus(
    query="The square root of 144 is 12",
    mode="high",
    min_confidence=0.8
)
print(result.verified)     # True
print(result.confidence)   # 0.95
```

| Parameter        | Type  | Default    | Description                    |
| ---------------- | ----- | ---------- | ------------------------------ |
| `query`          | str   | —          | Claim to verify                |
| `mode`           | str   | `"single"` | `single`, `high`, or `maximum` |
| `min_confidence` | float | `0.8`      | Minimum confidence threshold   |

### verify\_image(image\_path, claim)

<Info>New in v4.0.0</Info>

Verify claims about image content.

```python theme={null}
result = client.verify_image(
    image_path="photo.jpg",
    claim="This image contains a cat"
)
```

### verify\_batch(items)

Verify multiple items at once.

```python theme={null}
results = client.verify_batch([
    {"query": "2+2=4", "type": "math"},
    {"query": "3*3=9", "type": "math"},
])
print(results.summary.success_rate)
```

For `math` items, supply equality claims (e.g., `"x + x = 2*x"`) to receive proof results. Non-equality expressions (e.g., `"x + x"`) are returned as simplification-only results with `is_valid: false` and `status: "SIMPLIFIED"` — they are not reported as verified.

## CLI

```bash theme={null}
# Verify
qwed verify "2+2=4"

# Verify logic
qwed verify-logic "(AND (GT x 5) (LT y 10))"

# Verify code file
qwed verify-code -f script.py

# Batch verify
qwed batch -f queries.json
```

## Guards

The SDK includes security guards for protecting AI agent pipelines:

```python theme={null}
from qwed_sdk.guards import (
    RAGGuard,
    ExfiltrationGuard,
    MCPPoisonGuard,
    SelfInitiatedCoTGuard,
    SovereigntyGuard,
    SystemGuard,
    ConfigGuard,
)

# Prevent RAG hallucinations from wrong document chunks
rag_guard = RAGGuard(max_drm_rate="1/10")
result = rag_guard.verify_retrieval_context(
    target_document_id="contract_v2",
    retrieved_chunks=chunks
)

# Block data exfiltration to unauthorized endpoints
exfil_guard = ExfiltrationGuard(allowed_endpoints=["https://api.openai.com"])
result = exfil_guard.verify_outbound_call(
    destination_url=url,
    payload=data
)

# Detect poisoned MCP tool definitions
mcp_guard = MCPPoisonGuard()
result = mcp_guard.verify_tool_definition(tool_schema)

# Block dangerous shell commands (v4.0.0)
sys_guard = SystemGuard()
result = sys_guard.verify_shell_command("rm -rf /")

# Detect plaintext secrets in config (v4.0.0)
cfg_guard = ConfigGuard()
result = cfg_guard.verify_config_safety(config_data)
```

See the [SDK Guards reference](/sdks/guards) for complete documentation.

## Environment variables

| Variable        | Description  |
| --------------- | ------------ |
| `QWED_API_KEY`  | API key      |
| `QWED_BASE_URL` | API base URL |
