> ## 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.

# QWEDLocal — client-side verification

> Run QWED verification directly in your code without a backend server. Local execution, model-agnostic support, and deterministic result caching.

## Why QWEDLocal?

### No backend server needed

* Run verification directly in your application
* No infrastructure to manage
* Suitable for prototyping, scripts, and small projects

### Local execution

* Your API keys stay on your machine
* Your data does not touch QWED servers
* Useful for HIPAA, GDPR, and sensitive-data workloads

### Model agnostic

* Works with any supported LLM — OpenAI, Anthropic, Gemini
* Works with local models via Ollama
* Works with any OpenAI-compatible API

### Deterministic caching

* Cached results return without an LLM round-trip
* Repeated queries skip the LLM call
* Cache hits avoid network latency

***

## Installation

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

**Dependencies:**

```bash theme={null}
# For different LLM providers
pip install openai         # OpenAI + Ollama
pip install anthropic      # Anthropic Claude
pip install google-generativeai  # Google Gemini

# For verification engines
pip install sympy          # Math verification
pip install z3-solver      # Logic verification

# For caching and CLI
pip install colorama click
```

***

## Quick start

### Option 1: Ollama (no per-call cost)

```bash theme={null}
# 1. Install Ollama
# Visit: https://ollama.com

# 2. Pull a model
ollama pull llama3

# 3. Start Ollama
ollama serve
```

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

client = QWEDLocal(
    base_url="http://localhost:11434/v1",
    model="llama3"
)

result = client.verify_math("What is 2+2?")
print(result.verified)  # True
print(result.value)  # 4
```

### Option 2: OpenAI

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

client = QWEDLocal(
    provider="openai",
    api_key="sk-proj-...",
    model="gpt-4o-mini"  # Budget-friendly!
)

result = client.verify_math("What is the derivative of x^2?")
print(result.verified)  # True
print(result.value)  # 2*x
```

### Option 3: Anthropic Claude

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

client = QWEDLocal(
    provider="anthropic",
    api_key="sk-ant-...",
    model="claude-3-haiku-20240307"
)

result = client.verify("What is 5 factorial?")
```

***

## Verification engines

### 1. Math verification (SymPy)

```python theme={null}
result = client.verify_math("What is the integral of 2x?")
print(result.value)  # x**2
print(result.evidence)  # {"method": "sympy_eval", ...}
```

### 2. Logic verification (Z3)

```python theme={null}
result = client.verify_logic("Is (p AND NOT p) satisfiable?")
print(result.value)  # FALSE (contradiction!)
print(result.evidence)  # {"method": "z3_sat", ...}
```

### 3. Code security (AST)

```python theme={null}
code = """
def safe_function():
    return 42
"""

result = client.verify_code(code)
print(result.value)  # "SAFE"
```

**Dangerous code detection:**

```python theme={null}
dangerous_code = """
import os
eval(user_input)
"""

result = client.verify_code(dangerous_code)
print(result.value)  # "UNSAFE"
print(result.evidence["dangerous_patterns"])
# ["Dangerous function: eval"]
```

***

## Deterministic caching

Caching avoids redundant LLM calls.

```python theme={null}
# First call - hits LLM ($$$)
result = client.verify_math("2+2")
# -> 🔬 QWED Verification | Math Engine
# -> 📝 LLM Response: 4
# -> ✅ VERIFIED → 4

# Second call - from cache (FREE!)
result = client.verify_math("2+2")
# -> ⚡ Cache HIT (saved API call!)
# -> Returns instantly!
```

**Cache stats:**

```python theme={null}
stats = client.cache_stats
print(f"Hit rate: {stats.hit_rate:.1%}")
print(f"Hits: {stats.hits}, Misses: {stats.misses}")
```

**Disable caching:**

```python theme={null}
client = QWEDLocal(
    provider="openai",
    api_key="...",
    cache=False  # Always fresh
)
```

***

## CLI tool

### One-shot verification

```bash theme={null}
# Basic usage
qwed verify "What is 2+2?"

# With specific provider
qwed verify "derivative of x^2" --provider openai --model gpt-4o-mini

# With Ollama
qwed verify "5!" --base-url http://localhost:11434/v1 --model llama3

# Quiet mode (for scripts)
qwed verify "2+2" --quiet
```

### Interactive mode

```bash theme={null}
qwed interactive

# Output:
🔬 QWED Interactive Mode
Type 'exit' or 'quit' to quit

> What is 2+2?
🔬 QWED Verification | Math Engine
📝 LLM Response: 4
✅ VERIFIED → 4

> exit
```

### Cache management

```bash theme={null}
# View cache stats
qwed cache stats

# Clear cache
qwed cache clear
```

### Help

```bash theme={null}
qwed --help
qwed verify --help
qwed interactive --help
```

***

## Cost comparison

| Tier        | Monthly cost   | LLM options                    | Use cases                      |
| ----------- | -------------- | ------------------------------ | ------------------------------ |
| **Local**   | **\$0**        | Ollama (Llama 3, Mistral, Phi) | students, privacy, development |
| **Budget**  | **\~\$5-10**   | GPT-4o-mini, Gemini Flash      | startups, prototypes           |
| **Premium** | **\~\$50-100** | GPT-4, Claude Opus             | enterprises, production        |

Caching reduces repeated-query cost by skipping the LLM call.

***

## Privacy and security

### Local-only data flow

**QWEDLocal architecture:**

```text theme={null}
┌─────────────────────────────────────┐
│ Your Machine                        │
│                                     │
│  ┌──────────────┐                  │
│  │ QWEDLocal    │                  │
│  │ (Your Code)  │                  │
│  └──────┬───────┘                  │
│         │                           │
│         ├─→ LLM API (Direct)       │
│         │   (OpenAI/Anthropic/     │
│         │    Ollama)                │
│         │                           │
│         └─→ Verifiers (Local)      │
│             SymPy, Z3, AST          │
│                                     │
│  ❌ NO data sent to QWED!          │
└─────────────────────────────────────┘
```

**Use cases:**

* Healthcare (HIPAA compliance)
* Finance (PCI-DSS compliance)
* Government (classified data)
* Privacy-focused applications

***

## Advanced configuration

### Custom cache settings

```python theme={null}
client = QWEDLocal(
    provider="openai",
    api_key="...",
    cache=True,
    cache_ttl=3600  # 1 hour TTL (default: 24 hours)
)
```

### Environment variables

```bash theme={null}
export QWED_API_KEY="sk-..."
export QWED_QUIET=1  # Disable colorful output
```

### Quiet mode (no branding)

```python theme={null}
import os
os.environ["QWED_QUIET"] = "1"

client = QWEDLocal(...)
result = client.verify("2+2")
# No colored output, just results
```

***

## Examples

### Example 1: fact-checking pipeline

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

client = QWEDLocal(base_url="http://localhost:11434/v1", model="llama3")

facts_to_check = [
    "2+2=4",
    "The derivative of x^2 is 2x",
    "Paris is the capital of France"
]

for fact in facts_to_check:
    result = client.verify(fact)
    print(f"{fact}: {'✅' if result.verified else '❌'}")
```

### Example 2: code review automation

```python theme={null}
import os
from qwed_sdk import QWEDLocal

client = QWEDLocal(provider="openai", api_key=os.getenv("OPENAI_API_KEY"))

code_snippets = [
    "def add(a, b): return a + b",
    "exec(user_input)",  # Dangerous!
    "import os; os.system('rm -rf /')"  # Very dangerous!
]

for code in code_snippets:
    result = client.verify_code(code)
    status = "🟢 SAFE" if result.verified else "🔴 UNSAFE"
    print(f"{status}: {code[:30]}...")
    if not result.verified:
        print(f"  Issues: {result.evidence['dangerous_patterns']}")
```

### Example 3: batch processing with cache

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

client = QWEDLocal(provider="openai", api_key="...")

# Process 1000 math queries
queries = ["What is 2+2?"] * 500 + ["What is 3+3?"] * 500

for q in queries:
    result = client.verify_math(q)
    # First 2 calls hit LLM, rest cached!

print(client.cache_stats)
# Hit rate: 99.8%! (Saved $$$)
```

***

## Troubleshooting

### LLM not available

```python theme={null}
# Check if Ollama is running
curl http://localhost:11434/v1/models

# Start Ollama
ollama serve
```

### Missing dependencies

```bash theme={null}
# Install verification engines
pip install sympy z3-solver

# Install LLM clients
pip install openai anthropic google-generativeai
```

### Cache issues

```bash theme={null}
# Clear cache
qwed cache clear

# Or in Python
client._cache.clear()
```

***

## Learn more

* [CLI guide](/advanced/cli) — complete CLI reference
* [Ollama integration](/advanced/ollama) — local LLMs
* [LLM configuration](/getting-started/llm-configuration) — provider setup
* [Full documentation](https://docs.qwedai.com)

***

## Contributing

Contributions welcome. See the [contributing guide](https://github.com/QWED-AI/qwed-verification/blob/main/CONTRIBUTING.md).

***

## License

Apache 2.0 — see [LICENSE](https://github.com/QWED-AI/qwed-verification/blob/main/LICENSE).

***

## Support

If QWEDLocal saved you time or money, give us a star! ⭐

**Made with 💜 by the QWED team**
