Installation
Quick start
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 for details.Async client
Methods
verify(query)
Auto-detect and verify any claim.verify_math(expression)
Verify mathematical expressions.verify_logic(query)
Verify logical constraints (QWED-Logic DSL).verify_code(code, language)
Check code for security vulnerabilities.verify_sql(query, schema_ddl, dialect)
Validate SQL queries against a schema.verify_fact(claim, context)
New in v4.0.0
verify_stats(query, file_path)
New in v4.0.0
verify_consensus(query, mode, min_confidence)
New in v4.0.0
| 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)
New in v4.0.0
verify_batch(items)
Verify multiple items at once.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.
Verification cache
qwed_sdk.cache.VerificationCache is the persistent SQLite-backed cache for verification results. It reduces LLM cost on repeated queries.
Cache entries are context-bound. A hit requires an exact match of both the normalized query and the trust-bound CacheContext.
A mismatch on any context dimension is a deterministic miss. The cache never falls back to a query-only match. This prevents cross-provider, cross-model, cross-policy, and cross-tenant replay of VERIFIED results.
CacheContext
Every get() and set() call requires a CacheContext. All fields participate in the cache key.
| Field | Type | Required | Description |
|---|---|---|---|
provider | str | yes | Provider or API endpoint identifier (e.g., "openai"). |
model | str | yes | Model or deployment name (e.g., "gpt-4o"). |
policy_version | str | yes | Verifier policy version string (e.g., "v1"). |
tenant_id | Optional[str] | no | Tenant or session scope identifier. |
env_fingerprint | Optional[str] | no | Environment or configuration fingerprint for extra binding. |
Usage
Miss conditions
cache.get(query, context) returns None when any of the following holds:
- No entry exists for this
(query, context)pair. - The stored entry has expired (TTL, default 24 hours).
- The stored context fingerprint does not match
context(replay guard). - The entry uses the legacy v1 schema. The cache never returns legacy rows.
Constructor options
cache_dir— Directory for the SQLite database. Defaults to~/.qwed/cache.ttl— Time-to-live in seconds. Defaults to 24 hours.
CLI
Verification cache
qwed_sdk.cache provides a context-bound SQLite cache for verification results.
A cache hit requires an exact match of both the normalized query and the trust-bound CacheContext. Any mismatch on a context dimension yields a deterministic miss — the cache never crosses trust boundaries. The cache also ignores legacy entries that lack a context fingerprint.
CacheContext
Trust-bound context dimensions required for every cache operation. All fields participate in the cache key; omitting or changing any field causes a deterministic cache miss.
Provider or API endpoint identifier (for example,
"openai", "claude").Model or deployment name (for example,
"gpt-4o").Verifier policy version string (for example,
"v1").Tenant or session scope identifier. Use to prevent cross-tenant replay.
Environment or config fingerprint for additional binding.
VerificationCache(cache_dir=None, ttl=86400)
Directory for the SQLite cache database.
Time-to-live in seconds (default: 24 hours).
get() treats entries older than ttl as a miss and deletes them on access.MAX_ENTRIES = 1000. When set() grows the table past the cap, set() evicts the least-recently-accessed entries.
get(query, context)
Return the cached result for (query, context), or None on miss.
get() returns None when:
- No entry exists for the
(query, context)pair. - The entry has expired (older than
ttl). - The stored context fingerprint does not match
context(defence-in-depth replay guard).
The verification query string. Normalized (lowercased, whitespace-collapsed) before hashing.
Trust-bound context that must match exactly. Omitting this argument raises
TypeError.The cached result dict, or
None on any miss.set(query, result, context)
Store a verification result bound to (query, context).
The composite primary key (key, context_fingerprint) keeps identical queries under different contexts as independent entries.
The verification query string.
Verification result to cache.
set() serializes this dict as JSON.Trust-bound context to bind this entry to.
clear()
Remove all cached entries and reset stats.
get_stats()
Return a CacheStats dataclass with hits, misses, total_entries, cache_size_bytes, and a hit_rate property.
print_stats()
Print a formatted summary of cache statistics to stdout. Uses ANSI colors when colorama is installed.
Breaking change (Issue #187).
get() and set() now require a CacheContext argument. Calls like cache.get("2+2") or cache.set("2+2", result) raise TypeError. The on-disk schema is cache_v2 with composite PRIMARY KEY (key, context_fingerprint). The cache never returns entries from the legacy v1 cache table.Guards
The SDK includes security guards for protecting AI agent pipelines:Environment variables
| Variable | Description |
|---|---|
QWED_API_KEY | API key |
QWED_BASE_URL | API base URL |