AnthropicSchemaSanitizer
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
Strip the keywords Anthropic native structured output rejects, folding each into the node's description so the model still honors the intent.
Sanitize a single schema node, then recurse into its children.
Recurse into every child schema of the given node.
Rewrite a union "type" array into the anyOf form Anthropic documents.
Append the given constraint notes to the node's description.
Format a natural-language note for a constraint Anthropic rejects.
Pluralize a character count for a string-length note.
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.
at line 86
static protected array
node(array $schema)
Sanitize a single schema node, then recurse into its children.
at line 138
static protected array
children(array $schema)
Recurse into every child schema of the given node.
at line 163
static protected array
expandUnionType(array $schema)
Rewrite a union "type" array into the anyOf form Anthropic documents.
at line 197
static protected array
describe(array $schema, array $notes)
Append the given constraint notes to the node's description.
at line 217
static protected string|null
note(string $keyword, mixed $value)
Format a natural-language note for a constraint Anthropic rejects.
at line 245
static protected string
characters(mixed $value)
Pluralize a character count for a string-length note.
at line 253
static protected bool
isSupportedEnum(mixed $enum)
Determine if every member of the given enum is a type Anthropic accepts.