Skip to content

LearnGenerate & answer

JSON Schema

A JSON vocabulary for describing the shape of JSON data: types, required properties, enums, patterns and ranges.

In DocSlurpGlossary entry

On this page

JSON Schema is a standard way to describe what valid JSON looks like. A schema is itself JSON: it names the properties an object may have, their types, which are required, and constraints such as allowed values, regular-expression patterns and numeric ranges.

{
  "type": "object",
  "properties": {
    "vendor": { "type": "string", "description": "Company providing the service" },
    "uptime_percent": { "type": "number", "minimum": 0, "maximum": 100 },
    "severity": { "type": "string", "enum": ["P1", "P2", "P3"] }
  },
  "required": ["vendor", "uptime_percent"]
}

{"vendor": "Acme Hosting", "uptime_percent": 99.95} is valid. {"uptime_percent": 140} fails twice: vendor is missing and 140 exceeds the maximum.

In LLM work a schema does two jobs. It tells the model what to produce, through property names and description fields, and it lets your code check what came back. That is the basis of structured output and of tool calling, where each tool’s arguments are described by a schema.

The gotcha

A schema checks shape, not truth. "uptime_percent": 99.5 passes even when the document says 99.95. Constraints catch impossible values, never plausible wrong ones. Pair the schema with a request for the source text behind each field, so a reviewer can check values against the page.

Implementations also differ in which keywords they honor. Providers that enforce schemas during decoding often support only a subset, so test the schema against the exact provider and validator you use.

In DocSlurp

In DocSlurp

A project outputSchema is a JSON Schema object. DocSlurp turns its top-level properties into fields and checks required, enum, pattern, minimum and maximum; nested objects and arrays come back as values but are not validated inside (structuredSchemaFromJsonSchema in core/worker/src/stages/structured-extract.ts, core/packages/shared/src/structured.ts). See structured extraction.

Sources

Jump to