AISchemaGate

Live playground

Valid JSON ≠ Right JSON: Live LLM Contract & Auto-Repair Checker

Three structured outputs that satisfy a type-only JSON schema, including one sent with strict: true. They still break a production agent. Edit the contract and the model output, then generate the violation report, the repair prompt, and the sanitized payload. No signup, and no request leaves the browser.

Read the architectural version: AISchemaGate vs. Zod / Pydantic.

Every value has a legal JSON type. total_amount is negative, currency is not an ISO code in the allowed set, and customer_email is a raw address that must be masked before it is logged or stored.

Top-level fields only: type, required, enum, pattern, min, max, length, compliance_mode, and mask / hash / drop / redact. A nested object is accepted or rejected as a whole; child keys are not checked. Unknown YAML keys are rejected. Nothing is uploaded.

Checking the example…

The same check, in five lines

Output.json() only promises a JSON value. validateOnly / validate_only run the contract named extract_invoice_v1. Forward result.payload when result.ok is true. That object is already masked. To re-prompt, pass an OpenAI-shaped client to completion({ autoRepair: true }) or completion(..., auto_repair=True). The default budget is 2 retries, hard-capped at 5. The repair hint is a user message, not a system message.

$ npm i @nightmoose/aischemagate$ pip install aischemagate
import { generateText, Output } from 'ai';
import { LLMGate } from '@nightmoose/aischemagate';
const gate = new LLMGate({ apiKey: process.env.CONTRACTGATE_API_KEY!, contractId: 'extract_invoice_v1' });
const { output } = await generateText({ model: 'openai/gpt-4o-mini', prompt, output: Output.json() });
const result = await gate.validateOnly(output);
Vercel AI SDK calls the model. AISchemaGate checks the object that came back. Same API key as DataContractGate.