Skip to documentation
Documentation navigation

Documentation navigation

Documentation / guides

Portable JSON Schema

Use the bounded JSON Schema subset shared by provider codecs.

developer

ValidateOutputSchema accepts a deliberately small, deterministic JSON Schema subset so one OutputSchema can be encoded by multiple provider codecs.

Supported shapes

ShapeAllowed keywords
Roottype: "object" only
Objecttype, description, properties, required, additionalProperties: false
Arraytype, description, items containing one schema object
Scalartype, description, optional type-matching enum
Scalar typesstring, boolean, number, integer

Objects with properties must list every property in required; required names must be known and unique. Arrays use one homogeneous items schema, not tuple arrays. additionalProperties is required on every object and must be false. Unknown keywords, $ref, composition, numeric constraints, and string constraints are rejected.

{
  "type": "object",
  "properties": {
    "items": {
      "type": "array",
      "items": {"type": "string"}
    }
  },
  "required": ["items"],
  "additionalProperties": false
}
schema := json.RawMessage(`{"type":"object","properties":{"answer":{"type":"string"}},"required":["answer"],"additionalProperties":false}`)
if err := inference.ValidateOutputSchema(inference.OutputSchema{
	Name: "answer", Schema: schema,
}); err != nil {
	panic(err)
}

The validator bounds schema bytes at 1 MiB, nesting depth at 64, and the total property count at 1024. Duplicate object members are detected after JSON string unescaping, including escaped duplicate property names.

Proof

Related: Schema validation, OutputSchema.

← back to documentation