Open source · AI & LLM

AI Output JSON Schema Checker

Validate structured model output against JSON Schema and repair boundaries.

v0.1.0 · Node.js 22+ · MIT

Browse the public repository · View releases

This dependency-free, offline reporter checks one saved model-output JSON file against one local, explicit schema profile. It separates malformed or unreadable output from a valid document that fails schema rules. An optional local policy can normalize named fields; every change is logged by type and digest, and the transformed copy is checked again. Nothing is sent to a model or written back to disk.

This walkthrough uses the tool's public README and checked-in example files. Run the command from a repository checkout with Node.js 22+.

Run the checked-in example

node bin/ai-output-json-schema-checker.mjs --root examples --schema record.schema.json --output good.output.json
node bin/ai-output-json-schema-checker.mjs --root examples --schema record.schema.json --output bad.output.json
node bin/ai-output-json-schema-checker.mjs --root examples --schema record.schema.json --output normalizable.output.json --normalization-policy normalization-policy.json
node bin/ai-output-json-schema-checker.mjs --root examples --schema record.schema.json --output good.output.json --report check.report.json
node bin/ai-output-json-schema-checker.mjs --help
npm run check

Read the result

The first, third and fourth checks exit 0; the second exits 1. Completed and incomplete checks emit one JSON report on stdout and a fixed, human-readable status and finding count on stderr. Add --json to suppress only that human report summary; invalid configuration still leaves stdout empty and emits a fixed diagnostic on stderr. --help alone prints usage and exits 0. The summary contains no input values or identifiers. Optional --report FILE writes the same JSON bytes to a named file under the declared root; without it, no file is written. Programmatic callers can import checkOutput, exitCodeFor, RULESEVERITY, and TOOLID from src/index.mjs. checkOutput accepts {root, schema, output, normalizationPolicy?, limits?, now?}; now is an injected clock function, defaulting to Date.now.

Scope

This tool does not execute model calls, contact providers, infer a schema, implement full JSON Schema, attest to the truth of a model response, prove external approval, perform implicit coercion, or modify output documents. It validates only the saved evidence and profile described above.