Skip to main content

Getting Started with QWED

Learn how to set up and run QWED in your development environment. :::danger Common Mistake Don’t call your LLM directly! QWED needs to run as a backend server with YOUR LLM API keys configured in environment variables. See Common Pitfalls for details. :::

Architecture Overview

QWED uses a backend server model:
Your Application
  ↓ (SDK calls)
QWED Backend Server (you run this!)
  ├─ Your LLM API Key (from .env)
  ├─ LLM calls (OpenAI/Anthropic/etc)
  ├─ Formal Verifiers (SymPy, Z3)
  └─ Returns verified result

Step 1: Clone & Install

# Clone the repository
git clone https://github.com/QWED-AI/qwed-verification.git
cd qwed-verification

# Install Python dependencies
pip install -r requirements.txt

Step 2: Configure LLM Provider

QWED is model agnostic - choose any LLM based on your needs:

Create Environment File

# Copy example configuration
cp .env.example .env

Choose Your LLM Provider

Edit .env and add your API key for ONE provider:
# .env
ACTIVE_PROVIDER=openai
OPENAI_API_KEY=sk-proj-...
Get API Key: https://platform.openai.com/api-keys
:::tip See Full Configuration Guide For AWS Bedrock and more options, see: LLM Configuration :::

Step 3: Run QWED Backend Server

# Start the backend server
python -m qwed_api

# You should see:
# INFO: Uvicorn running on http://0.0.0.0:8000
Keep this terminal running! The server needs to stay active.

Step 4: Install SDK

In a new terminal, install the QWED SDK in your project:
pip install qwed

Step 5: Use the SDK

Connect your application to the local QWED backend:
from qwed import QWEDClient

# Connect to local backend
client = QWEDClient(
    api_key="qwed_local",  # Local auth key
    base_url="http://localhost:8000"
)

# Verify a mathematical claim
result = client.verify("Is 2+2 equal to 4?")

print(result.verified)  # True
print(result.evidence)  # {"calculated": 4, "claimed": 4}

Verify Installation

Run this test to ensure everything is working:
from qwed import QWEDClient

client = QWEDClient(
    api_key="qwed_local",
    base_url="http://localhost:8000"
)

# Test 1: Math verification
assert client.verify("2+2=4").verified == True
print("✅ Math verification works!")

# Test 2: Error detection
assert client.verify("2+2=5").verified == False
print("✅ Error detection works!")

# Test 3: Code security
result = client.verify_code("eval(user_input)", language="python")
assert result.blocked == True
print("✅ Security detection works!")

print("\n🎉 QWED is working correctly!")

Next Steps

Once your integration is working:

Troubleshooting

Backend won’t start

Problem:
Error: ANTHROPIC_API_KEY environment variable not set
Solution: Check your .env file has the correct API key for your chosen provider.

SDK can’t connect

Problem:
Connection refused to http://localhost:8000
Solution:
  1. Make sure backend is running (python -m qwed_api)
  2. Check backend terminal for errors
  3. Verify port 8000 is not blocked

Wrong results

Problem: Verification results are incorrect or unexpected. Solution:
  1. Check which LLM provider you configured
  2. Verify your API key is valid
  3. See Testing Guide for detailed diagnostics

Need Help?