Interface JSONSchema

Complete JSON Schema definition for structured outputs.

Remarks

This interface supports the commonly used JSON Schema keywords for defining structured LLM outputs. It's designed to be compatible with OpenAI's structured output API and similar implementations.

interface JSONSchema {
    type?: JSONSchemaType | JSONSchemaType[];
    title?: string;
    description?: string;
    default?: unknown;
    enum?: unknown[];
    const?: unknown;
    minLength?: number;
    maxLength?: number;
    pattern?: string;
    format?: JSONSchemaStringFormat;
    minimum?: number;
    maximum?: number;
    exclusiveMinimum?: number;
    exclusiveMaximum?: number;
    multipleOf?: number;
    items?: JSONSchema | JSONSchema[];
    minItems?: number;
    maxItems?: number;
    uniqueItems?: boolean;
    additionalItems?: boolean | JSONSchema;
    prefixItems?: JSONSchema[];
    contains?: JSONSchema;
    properties?: Record<string, JSONSchema>;
    required?: string[];
    additionalProperties?: boolean | JSONSchema;
    patternProperties?: Record<string, JSONSchema>;
    minProperties?: number;
    maxProperties?: number;
    propertyNames?: JSONSchema;
    dependentRequired?: Record<string, string[]>;
    dependentSchemas?: Record<string, JSONSchema>;
    allOf?: JSONSchema[];
    anyOf?: JSONSchema[];
    oneOf?: JSONSchema[];
    not?: JSONSchema;
    if?: JSONSchema;
    then?: JSONSchema;
    else?: JSONSchema;
    $ref?: string;
    $defs?: Record<string, JSONSchema>;
    examples?: unknown[];
    readOnly?: boolean;
    writeOnly?: boolean;
    deprecated?: boolean;
}

Properties

The data type of the schema

title?: string

Human-readable title for the schema

description?: string

Description of what the schema represents

default?: unknown

Default value if not provided

enum?: unknown[]

Enumeration of allowed values

const?: unknown

Constant value (must be exactly this)

minLength?: number

Minimum string length

maxLength?: number

Maximum string length

pattern?: string

Regex pattern the string must match

String format validator

minimum?: number

Minimum value (inclusive)

maximum?: number

Maximum value (inclusive)

exclusiveMinimum?: number

Minimum value (exclusive)

exclusiveMaximum?: number

Maximum value (exclusive)

multipleOf?: number

Value must be a multiple of this number

Schema for array items

minItems?: number

Minimum number of items

maxItems?: number

Maximum number of items

uniqueItems?: boolean

All items must be unique

additionalItems?: boolean | JSONSchema

Schema for items after items tuple schemas

prefixItems?: JSONSchema[]

Prefix items (for tuple validation)

contains?: JSONSchema

Schema that must validate at least one item

properties?: Record<string, JSONSchema>

Property definitions for object

required?: string[]

Required property names

additionalProperties?: boolean | JSONSchema

Schema for properties not in properties

patternProperties?: Record<string, JSONSchema>

Pattern-based property schemas

minProperties?: number

Minimum number of properties

maxProperties?: number

Maximum number of properties

propertyNames?: JSONSchema

Property names must match this schema

dependentRequired?: Record<string, string[]>

Dependencies between properties

dependentSchemas?: Record<string, JSONSchema>

Schema dependencies

allOf?: JSONSchema[]

Must match all schemas

anyOf?: JSONSchema[]

Must match at least one schema

oneOf?: JSONSchema[]

Must match exactly one schema

Must not match this schema

Conditional schema application

then?: JSONSchema

Schema if if passes

else?: JSONSchema

Schema if if fails

$ref?: string

Reference to another schema

$defs?: Record<string, JSONSchema>

Schema definitions for $ref

examples?: unknown[]

Examples of valid values

readOnly?: boolean

Whether this value is read-only

writeOnly?: boolean

Whether this value is write-only

deprecated?: boolean

Deprecation flag