Response Schema Support
Response Schema Support
The response_schema parameter allows you to request structured, machine-readable responses from the Statement Agent API. Instead of receiving only free-form text, you can define the expected output format and have the agent return data that conforms to your schema.
This is particularly useful for:
- Building automated workflows
- Populating dashboards and reports
- Extracting structured business insights
- Integrating agent responses into applications and APIs
- Reducing post-processing and parsing requirements
When a valid schema is provided, the agent attempts to generate output that matches the specified structure. If successful, the parsed result is returned in the choices[].structured field of the response.
Supported Schema Fields
The Statement API supports a subset of JSON Schema concepts designed for common structured output use cases.
| Field | Type | Description |
|---|---|---|
type | string | Required. Defines the data type for the schema or field. |
properties | object | Required for object schemas. Defines the available object properties. |
items | object or array | Required for array schemas. Defines the structure of array elements. |
required | array | Optional list of property names that must be present in an object. |
description | string | Optional field description used to provide additional context to the agent. |
enum | array | Optional list of allowed values for a field. |
default | any | Optional default value. The value must match the declared field type. |
Supported Types
The following schema types are supported:
| Type |
|---|
object |
array |
string |
number |
boolean |
null |
Object Schema Requirements
Object schemas must define a non-empty properties object.
Example
{
"type": "object",
"properties": {
"summary": {
"type": "string"
},
"confidence": {
"type": "number"
}
}
}
Validation Rules
propertiesmust be present.propertiescannot be empty.- Every property listed in
requiredmust also exist inproperties.
Valid Example
{
"type": "object",
"properties": {
"summary": {
"type": "string"
}
},
"required": ["summary"]
}
Invalid Example
{
"type": "object",
"properties": {
"summary": {
"type": "string"
}
},
"required": ["summary", "risk_level"]
}
The example above is invalid because risk_level is listed as required but is not defined in properties.
Array Schema Requirements
Array schemas must define an items field describing the structure of each array element.
Example
{
"type": "array",
"items": {
"type": "string"
}
}
Array of Objects Example
{
"type": "array",
"items": {
"type": "object",
"properties": {
"metric": {
"type": "string"
},
"value": {
"type": "number"
}
}
}
}
Enum Support
Use enum to restrict a field to a predefined set of values.
Example
{
"type": "string",
"enum": [
"low",
"medium",
"high"
]
}
The generated response will attempt to use only one of the specified values.
Default Values
The default field can be used to provide a fallback value for a schema property.
The default value must match the property's declared type.
Example
{
"type": "string",
"default": "unknown"
}
Invalid Example
{
"type": "number",
"default": "unknown"
}
The example above is invalid because the default value is a string while the declared type is number.
Example Response Schema
The following schema requests a structured business analysis response:
{
"type": "object",
"properties": {
"summary": {
"type": "string",
"description": "Brief business summary"
},
"revenue_growth": {
"type": "number"
},
"risk_level": {
"type": "string",
"enum": [
"low",
"medium",
"high"
]
}
},
"required": [
"summary",
"revenue_growth",
"risk_level"
]
}
Validation Rules
Before processing a request, the API validates the supplied schema.
A schema is considered valid when:
- A supported
typeis specified. - Object schemas include a non-empty
propertiesfield. - Array schemas include an
itemsdefinition. - All entries in
requiredexist inproperties. - Any
defaultvalue matches the declared field type. - Any
enumdefinition contains at least one valid value.
Requests containing invalid schemas will be rejected before agent execution begins.
Notes
- The schema format is intentionally lightweight and optimized for structured AI responses.
- Schema validation occurs before the request is routed to an agent.
- Structured output is returned in
choices[].structuredonly when the generated response successfully conforms to the provided schema. - The original generated content is always available in
choices[].message.content. - Complex or deeply nested schemas may reduce generation reliability. For best results, keep schemas concise and focused on the data you need.