# JSON schema output validate

`json-schema-output-validate` · version 1.0.0 · JSON & JSONL · free, no key needed

Validate JSON (e.g. LLM output) against a Draft 2020-12 schema subset; returns spec output units with JSON Pointers.

**Use when you need to: validate llm structured output against draft 2020-12 json schema · check model json response matches a 2020-12 schema · json schema 2020-12 basic output with keyword and instance locations.**

## Decide before calling

Read the [versioned contract](/v1/tools/json-schema-output-validate/versions/1.0.0) and the supported scope below. Reuse `json-schema-output-validate@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `json-schema-output-validate@1.0.0` for validate llm structured output against draft 2020-12 json schema. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- validate llm structured output against draft 2020-12 json schema
- check model json response matches a 2020-12 schema
- json schema 2020-12 basic output with keyword and instance locations
- find which fields of generated json break the schema
- validate json with local $ref and $defs schema
- flag or basic output format json schema validation
- בדיקת פלט JSON של מודל מול סכמת JSON 2020-12

## Not supported

- pattern, patternProperties, propertyNames, contains, if/then/else, dependent*, unevaluated* keywords (unsupported_input)
- remote, relative or anchor $ref and embedded $id resources (only "#..." JSON Pointer references)
- format assertion (format is an annotation and is ignored, as in the 2020-12 default vocabulary)
- repairing or coercing the instance
- detailed and verbose output structures

## Behavior

- Supported keywords: $schema (root, must be the 2020-12 meta-schema URI), $id (root only), $defs, $ref ("#" + RFC 6901 fragment, same document), allOf, anyOf, oneOf, not, type, enum, const, multipleOf, maximum, exclusiveMaximum, minimum, exclusiveMinimum, maxLength, minLength, required, properties, additionalProperties, maxProperties, minProperties, prefixItems, items, maxItems, minItems, uniqueItems. Ignored annotations: title, description, default, examples, deprecated, readOnly, writeOnly, format, $comment, contentEncoding, contentMediaType. Any other keyword is unsupported_input; a malformed keyword value is invalid_input with details.schema_location.
- output_format is "basic" when omitted. "flag" returns only {valid} and stops at the first failure (core 12.4.1). "basic" returns {valid, truncated, errors}: a flat pre-order list of output units (core 12.4.2) after the 12.4.3 condensation rules (applicator nodes without failures are dropped, a node with one child is replaced by it); branch units have kind "branch", failing assertions kind "assertion" with keyword and params.
- keyword_location is the dynamic RFC 6901 path through the schema and includes $ref; instance_location is the RFC 6901 path in the instance; absolute_keyword_location is present only when the root has an absolute-URI $id and the path crossed a $ref, as <$id>#<RFC 6901 fragment of the dereferenced location>.
- Keyword order inside each schema object is fixed: $ref, allOf, anyOf, oneOf, not, type, enum, const, multipleOf, maximum, exclusiveMaximum, minimum, exclusiveMinimum, maxLength, minLength, required (listed order), properties and additionalProperties (instance member names ascending by UTF-16 code units), maxProperties, minProperties, prefixItems and items (ascending index), maxItems, minItems, uniqueItems. Schema object key order never changes results.
- anyOf, oneOf and not report one assertion unit (params branch_count, passing_count) without branch details. A false subschema is reported under the keyword that applied it (properties/additionalProperties with params.property, items/prefixItems/allOf with params.index, $ref) or as false_schema at the root.
- type integer matches any number with a zero fractional part; string lengths count Unicode code points; enum, const and uniqueItems use JSON equality (key order ignored, 1 and 1.0 equal); multipleOf is exact on the shortest round-trip decimal of each number; uniqueItems params.indexes is the first equal pair by lowest second index.
- Work: 1 unit per subschema application plus 1 per object member scanned by properties/additionalProperties, per array element scanned by prefixItems/items or uniqueItems, and per required name; more than 20000 units, more than 64 nested applications, input over 65536 bytes or deeper than 32 levels is limit_exceeded. At most 100 assertion units are reported; truncated is true when more failures existed.

## Input

- `schema` (any JSON value, required): JSON Schema 2020-12 document (object or boolean) within the supported subset
- `instance` (any JSON value, required): Any JSON value to validate, for example parsed LLM output
- `output_format` (one of "basic", "flag", optional)

## Output

- `valid` (boolean, required)
- `truncated` (boolean, optional)
- `errors` (array of object, optional): max items 199

## Limits

- max input bytes: 65536
- max json depth: 32
- max evaluation depth: 64
- max evaluation work: 20000
- max errors: 100
- max output bytes: 262144

## Example

Request input:

```json
{
  "schema": {
    "type": "object",
    "required": [
      "name",
      "age"
    ],
    "properties": {
      "name": {
        "type": "string"
      },
      "age": {
        "type": "integer",
        "minimum": 0
      }
    },
    "additionalProperties": false
  },
  "instance": {
    "name": "Ada",
    "age": -1,
    "extra": true
  }
}
```

Response:

```json
{
  "result": {
    "valid": false,
    "truncated": false,
    "errors": [
      {
        "kind": "branch",
        "keyword_location": "",
        "instance_location": ""
      },
      {
        "kind": "assertion",
        "keyword_location": "/properties/age/minimum",
        "instance_location": "/age",
        "keyword": "minimum",
        "params": {
          "limit": 0
        }
      },
      {
        "kind": "assertion",
        "keyword_location": "/additionalProperties",
        "instance_location": "/extra",
        "keyword": "additionalProperties",
        "params": {
          "property": "extra"
        }
      }
    ]
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "json-schema-output-validate",
  "version": "1.0.0",
  "input": {
    "schema": {
      "type": "object",
      "required": [
        "name",
        "age"
      ],
      "properties": {
        "name": {
          "type": "string"
        },
        "age": {
          "type": "integer",
          "minimum": 0
        }
      },
      "additionalProperties": false
    },
    "instance": {
      "name": "Ada",
      "age": -1,
      "extra": true
    }
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/json-schema-output-validate/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"schema":{"type":"object","required":["name","age"],"properties":{"name":{"type":"string"},"age":{"type":"integer","minimum":0}},"additionalProperties":false},"instance":{"name":"Ada","age":-1,"extra":true}}'
```

The machine-readable contract is at [/v1/tools/json-schema-output-validate/versions/1.0.0](/v1/tools/json-schema-output-validate/versions/1.0.0).

### CLI

```sh
node cli.mjs run json-schema-output-validate 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [JSON schema batch validate](/tools/json-schema-batch-validate): Validate many JSON records against one Draft 2020-12 subset schema; per-record validity, error pointers, counts.
- [JSON schema required missing](/tools/json-schema-required-missing): List every property a JSON Schema 2020-12 "required" keyword demands but the instance lacks, with JSON Pointers.
- [JSON schema type mismatches](/tools/json-schema-type-mismatches): List every value whose JSON type fails a JSON Schema 2020-12 "type" keyword, with expected and actual types.
- [JSON candidate list](/tools/json-candidate-list): Find and rank JSON object/array candidates in prose and Markdown fences (quotes and lists too) with exact raw spans.
- [JSON schema errors format](/tools/json-schema-errors-format): Render JSON Schema output units as a 2020-12 basic or flag output document with fixed English error messages.
- [JSON fence extract](/tools/json-fence-extract): List Markdown fenced code blocks (CommonMark 0.31.2) with exact spans, unwrapped content and an RFC 8259 JSON check.
