class AnthropicSchemaSanitizer

Constants

protected NUMERIC_KEYWORDS

Numeric constraints rejected by Anthropic native structured output.

protected STRING_KEYWORDS

String constraints rejected by Anthropic native structured output.

protected ARRAY_KEYWORDS

Array constraints rejected beyond a "minItems" of 0 or 1.

protected OBJECT_KEYWORDS

Object constraints rejected beyond "properties", "required" and "additionalProperties".

protected SCHEMA_KEYWORDS

Subschema, annotation and identifier keywords outside the accepted subset.

protected REJECTED_KEYWORDS

Every keyword Anthropic native structured output rejects.

protected SUPPORTED_FORMATS

String formats accepted by Anthropic native structured output.

Methods

static array
sanitize(array $schema)

Strip the keywords Anthropic native structured output rejects, folding each into the node's description so the model still honors the intent.

static array
node(array $schema)

Sanitize a single schema node, then recurse into its children.

static array
children(array $schema)

Recurse into every child schema of the given node.

static array
expandUnionType(array $schema)

Rewrite a union "type" array into the anyOf form Anthropic documents.

static array
describe(array $schema, array $notes)

Append the given constraint notes to the node's description.

static string|null
note(string $keyword, mixed $value)

Format a natural-language note for a constraint Anthropic rejects.

static string
characters(mixed $value)

Pluralize a character count for a string-length note.

static bool
isSupportedEnum(mixed $enum)

Determine if every member of the given enum is a type Anthropic accepts.

Details

at line 75
static array sanitize(array $schema)

Strip the keywords Anthropic native structured output rejects, folding each into the node's description so the model still honors the intent.

Parameters

array $schema

Return Value

array

at line 86
static protected array node(array $schema)

Sanitize a single schema node, then recurse into its children.

Parameters

array $schema

Return Value

array

at line 138
static protected array children(array $schema)

Recurse into every child schema of the given node.

Parameters

array $schema

Return Value

array

at line 163
static protected array expandUnionType(array $schema)

Rewrite a union "type" array into the anyOf form Anthropic documents.

Parameters

array $schema

Return Value

array

at line 197
static protected array describe(array $schema, array $notes)

Append the given constraint notes to the node's description.

Parameters

array $schema
array $notes

Return Value

array

at line 217
static protected string|null note(string $keyword, mixed $value)

Format a natural-language note for a constraint Anthropic rejects.

Parameters

string $keyword
mixed $value

Return Value

string|null

at line 245
static protected string characters(mixed $value)

Pluralize a character count for a string-length note.

Parameters

mixed $value

Return Value

string

at line 253
static protected bool isSupportedEnum(mixed $enum)

Determine if every member of the given enum is a type Anthropic accepts.

Parameters

mixed $enum

Return Value

bool