Structured output instructs the model to respond with a machine-readable value — a JSON object, an array, or an enum string — instead of free prose. aisdk/core validates the response against your schema and surfaces the decoded PHP value inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/core/llms.txt
Use this file to discover all available pages before exploring further.
$result->output, so you never need to manually parse or guard the model’s reply.
Structured output requires the model to advertise
Capability::StructuredOutput. The SDK checks this before making any HTTP call and raises a CapabilityNotSupportedException for models that do not support it. Not every provider or model tier supports structured output — verify the capability list for your model before deploying.Basic object extraction
Pass aSchema::object() to ->output(). After ->run(), $result->output is a PHP array keyed by your property names:
Schema types
Schema is a single fluent class that covers every JSON Schema primitive. All factory methods accept an optional name and description:
Schema::string()
Schema::string()
{ "type": "string" }. Use for textual values.Schema::integer()
Schema::integer()
{ "type": "integer" }. Use for whole numbers.Schema::number()
Schema::number()
{ "type": "number" }. Use for floats and decimals.Schema::boolean()
Schema::boolean()
{ "type": "boolean" }.Schema::array()
Schema::array()
{ "type": "array", "items": { "type": "string" } }. The $items argument is a nested Schema instance.Schema::object()
Schema::object()
properties and an optional required array.Schema::enum()
Schema::enum()
{ "type": "string", "enum": ["low", "medium", "high"] }. Also accepted by ->output() directly.Property modifiers
Chain->required() and ->nullable() to any schema. Both return a new Schema instance (schemas are immutable):
Nested objects
Properties can be objects themselves. The SDK recursively serialises and validates the whole tree:Enum output
UseOutput::enum() when you want to constrain the model to one of a fixed set of string values. $result->output is then the chosen string:
Schema::enum() to ->output():
Output validation
The SDK runsSchemaValidator::validate() against the decoded JSON before returning TextResult. If the model’s response does not conform to the schema — a required property is missing, a type is wrong — a validation exception is thrown.
This means $result->output is always either a fully validated value or absent (when no ->output() schema was given). You do not need to guard against partial data.
Schema with array items
Extract a list of structured objects from a single prompt:Full reference: Output methods
| Method | Returns | Description |
|---|---|---|
->output(Schema $schema) | PendingTextRequest | Attaches a schema for structured JSON extraction. Objects and arrays use $result->output as a PHP array. |
->output(Output::enum([...])) | PendingTextRequest | Constrains output to one of the given string values. $result->output is the chosen string. |
$result->output | mixed | null when no ->output() was set. Array for object/array schemas. String for enum schemas. |