Skip to main content
The Schema Verifier goes beyond standard JSON validation. It combines Pydantic structure enforcement with Symbolic Math checks deeply embedded within the schema.

How It Works

It validates that:
  1. Structure: The output matches the required JSON keys and types.
  2. Logic: The numeric values inside the JSON are mathematically consistent (e.g., total == sum(items)).

Usage

schema = {
    "type": "object",
    "properties": {
        "items": {"type": "array", "items": {"type": "number"}},
        "total": {"type": "number"}
    },
    # QWED Extension: Math Logic
    "qwed:constraints": [
        "total == sum(items)"
    ]
}

response = client.verify_schema(
    obj={"items": [10, 20], "total": 30},
    schema=schema
)
# -> ✅ Verified

response = client.verify_schema(
    obj={"items": [10, 20], "total": 300}, # LLM hallucinations
    schema=schema
)
# -> ❌ MATH ERROR: total (300) != sum(items) (30)

Array validation

The Schema Verifier supports standard JSON Schema array keywords including uniqueItems.

uniqueItems — fail-closed validation

When a schema sets uniqueItems: true, the verifier checks that every element in the array is distinct. If an element is unhashable or otherwise cannot be compared deterministically (for example, an object containing a Python set), the verifier fails closed — it reports a uniqueness_validation_error issue instead of silently passing. This ensures that unverifiable arrays are never treated as valid. Issue types returned for uniqueItems:
Issue typeMeaning
uniqueness_violationDuplicate items were found in the array
uniqueness_validation_errorUniqueness could not be verified deterministically (fail-closed)
Example — duplicate items:
schema = {"type": "array", "uniqueItems": True}

result = client.verify_schema(obj=[1, 2, 2, 3], schema=schema)
# -> is_valid: false, issue_type: "uniqueness_violation"
Example — uncheckable items fail closed:
schema = {"type": "array", "uniqueItems": True}

# Items containing unhashable types cannot be compared deterministically
result = client.verify_schema(obj=[{"bad": {1, 2}}, {"bad": {3, 4}}], schema=schema)
# -> is_valid: false, status: "INVALID"
# -> issue_type: "uniqueness_validation_error"
# -> message: "uniqueItems could not be verified deterministically: ..."
This fail-closed behavior shipped in v5.1.0. See the changelog for the full release notes.

When to use

  • Invoice Processing: Ensure line items sum to the total.
  • Financial Reports: Ensure balance sheets balance.
  • Tax Forms: Ensure calculated fields match underlying data.