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.
The Reasoning Engine validates LLM reasoning traces using chain-of-thought parsing and multi-provider verification.
Features
- Chain-of-Thought Validation - Parse and verify reasoning steps
- Result Caching - LRU + Redis for repeated queries
- Multi-Provider Support - Anthropic, Azure OpenAI, Google Gemini, OpenAI
- Semantic Fact Extraction - Identify verifiable claims
Usage
from qwed_sdk import QWEDClient
client = QWEDClient(api_key="qwed_...")
result = client.verify_reasoning(
query="If all cats are mammals, and all mammals are animals, are all cats animals?",
enable_caching=True
)
print(result.is_valid) # True
print(result.confidence) # 0.95
print(result.reasoning_trace) # Step-by-step logic
print(result.cached) # True/False
Multi-Provider Verification
result = client.verify_reasoning(
query="Complex reasoning task...",
providers=["anthropic", "openai", "gemini", "azure"],
enable_cross_validation=True
)
print(result.provider_agreement) # 4/4
print(result.per_provider_results)
Caching
The engine caches results to avoid redundant LLM calls:
# First call - hits LLM
result1 = client.verify_reasoning(query, enable_caching=True)
print(result1.cached) # False
# Second call - from cache
result2 = client.verify_reasoning(query, enable_caching=True)
print(result2.cached) # True (instant!)
When verifying whether two arithmetic formulas produce the same result, the engine uses a safe AST-based evaluator instead of Python’s eval(). The evaluator only allows basic arithmetic operators (+, -, *, /, **) and numeric literals — any other expression is rejected. This prevents code-injection risks while still supporting numeric fallback checks during reasoning validation.
Chain-of-thought validation
cot_trace = """
Step 1: All cats are mammals (given)
Step 2: All mammals are animals (given)
Step 3: Therefore, all cats are animals (transitivity)
"""
result = client.validate_cot(
trace=cot_trace,
conclusion="All cats are animals"
)
print(result.valid_steps) # [1, 2, 3]
print(result.invalid_steps) # []
print(result.conclusion_valid) # True