Quick Start
Passstructured_output_schema when creating a task:
Polling via API
Use task.listMessages and look for thestructured_output_result event:
Push via Webhook
If you have a webhook configured, thetask_stopped callback includes the result in task_detail.structured_output:
How It Works
- You provide a JSON Schema with your task.create or task.sendMessage request.
- The agent runs normally — browsing, searching, coding, etc.
- When the task finishes (
stop_reason: finish), an extraction pass reads the conversation and produces a result matching your schema. - The result is delivered via task.listMessages and webhook callback.
The extraction is a post-processing step — it does not change how the agent works. The agent completes its task as usual, then a separate model extracts the structured result from the conversation.
Schema Lifecycle
The schema works as arm once, fire once:- Armed — passing
structured_output_schemain task.create or task.sendMessage arms the schema for extraction. - Not consumed on
ask— if the agent pauses to ask the user a question (stop_reason: ask), the schema stays armed. It will fire when the task eventually finishes. - Fired on
finish— when the task completes (stop_reason: finish), extraction runs and the schema is consumed. The result is delivered via the events API and webhook. - Re-arm to extract again — after the schema is consumed, subsequent task completions will not trigger extraction. To extract again, pass a new
structured_output_schemawith your next task.sendMessage.
Schema Requirements
The schema uses a strict subset of JSON Schema designed for reliable extraction. This ensures the output can always be deterministically validated and parsed.Root Type
The top-level schema must be"type": "object". You cannot use a bare string, array, or other primitive as the root.
Supported Types
Supported Keywords
Object Rules
Everyobject in the schema — root or nested — must follow these two rules:
additionalPropertiesmust befalse— Only explicitly defined properties are allowed. This prevents unexpected fields in the output.requiredmust list all properties — Every property defined inpropertiesmust appear in therequiredarray. Optional fields should use a nullable type instead (e.g.,{ "type": ["string", "null"] }).
Schema Reuse with $ref / $defs
Use $defs to define reusable sub-schemas and $ref to reference them. This is especially useful for recursive structures:
Nesting Depth
The maximum nesting depth for objects and arrays is 5 levels. Schemas exceeding this limit will be rejected.Unsupported Keywords
The following JSON Schema keywords are not supported and will cause a validation error if included:Result Format
The result always has three fields:
When
success is true:
The agent completed the task and value contains the extracted data:
success is false:
The extraction failed (e.g., the model call errored or the output didn’t match the schema). value is a zero-value fallback that conforms to your schema’s structure, and error explains what happened:
Multi-turn Conversations
The schema is consumed once per task stop. In a multi-turn conversation, you can attach a newstructured_output_schema to any task.sendMessage call:
- Send a message with schema → schema armed → agent runs → finishes → extraction fires → schema consumed
- Send a message without schema → agent runs → finishes → no extraction (previous schema was already consumed)
- Send a message with a new schema → re-arms with the new schema, replacing any previous one
- Agent pauses to ask a question (
stop_reason: ask) → schema not consumed, remains armed for when the task finishes
Examples
Simple extraction
Nullable fields
Nested objects with enum
Error Handling
Schema Validation Errors (HTTP 400)
If the schema is invalid, the request is rejected immediately:Extraction Errors (in result)
These appear assuccess: false with an error message. The value still contains a valid default conforming to your schema. Your application should check success before using value.