← Home Docs

✓ Contract Validation API

Correctover validates every LLM response across 6 dimensions before accepting it. This is the core differentiator: standard failover checks HTTP 200. Correctover verifies the contract. P50 = 22µs, P99 = 99µs.

Contract Types

ContractDimensionWhat It ValidatesP50
Contract.structure()StructureJSON schema compliance, required fields8µs
Contract.schema()SchemaField types match expected schema5µs
Contract.latency()LatencyResponse time within SLA threshold1µs
Contract.cost()CostToken usage within budget2µs
Contract.identity()IdentityModel identity matches (no substitution)3µs
Contract.integrity()IntegritySemantic coherence, no hallucinations22µs

Contract.Structure

Validates that the response conforms to a JSON Schema definition. Catches missing fields, wrong field types, and malformed responses.

Contract.structure(
    name="output_shape",
    schema={
        "type": "object",
        "properties": {
            "answer": {"type": "string"},
            "confidence": {"type": "number"},
            "citations": {
                "type": "array",
                "items": {"type": "string"},
                "minItems": 1
            }
        },
        "required": ["answer", "confidence"]
    }
)

Contract.Schema

Detects when the response structure drifts from the expected type — e.g. a provider returns Markdown instead of JSON, or changes field types.

Contract.schema(
    name="field_types",
    field_types={
        "temperature": float,
        "steps": list,
        "metadata.duration_ms": (int, float),
    }
)

Contract.Latency

Enforces response time SLAs. If a provider's response exceeds the threshold, it counts as a contract failure and triggers failover.

Contract.latency(
    name="p95_sla",
    max_ms=5000,        # Soft threshold
    hard_max_ms=10000,   # Hard cutoff
)

Contract.Cost

Prevents cost overruns from unexpected token usage. Particularly useful when failover lands on a more expensive model.

Contract.cost(
    name="budget",
    max_cents=2.0,
    alert_on_exceed=True,
)

Contract.Identity

Verifies the responding model matches what was requested. Detects silent model substitution — when a provider serves a cheaper model than billed.

Contract.identity(
    name="model_check",
    expected="gpt-4o-2024-11-20",
    allow_aliases=True,  # gpt-4o-2024-08-06 also OK
)

Contract.Integrity

The most advanced dimension. Uses semantic coherence checks to detect hallucinations, contradictions, and nonsensical output.

Contract.integrity(
    name="semantic_check",
    anti_hallucination=True,
    self_consistency=True,
    coherence_threshold=0.7,
)

Combining Contracts

Multiple contracts run in parallel on each response. All must pass for the response to be validated=True.

response = provider.complete(
    messages=[...],
    contracts=[
        Contract.structure("format", output_schema),
        Contract.latency("sla", max_ms=5000),
        Contract.cost("budget", max_cents=1.0),
    ]
)
if response.validated:
    # All 3 contracts passed
    print(response.metrics.contract_results)
    # → {"format": True, "sla": True, "budget": True}
Performance note: Contract validation runs in-process with zero external calls. The full 6-dimension validation suite completes in 22µs (P50) / 99µs (P99) — less than 0.01% of a typical LLM API call's latency budget.