Overview
To get an Agent run’s answer as a JSON object matching your own schema instead of freeform Markdown, request structured output by passing a schema when you start the run.Provide a schema
Passoutput_schema
(an OpenAI-style response_format object) to get
output.structured,
a JSON result shaped by your schema, in addition to the usual cited
output.text
report.
output.grounding looks like the following,
one entry per groundable field, each citing back into
output.sources
by source_id:
Schema validity
Create validatesoutput_schema’s wrapper shape, including type, and
json_schema.name / schema / strict for type json_schema, before
billing anything, and rejects a malformed one there. It does not validate
the schema’s content.
For strict: true, every object in the schema needs its own
additionalProperties: false, including nested ones like the array item
object above. Create accepts a schema missing it, but the run then fails
with stop_reason: invalid_output.
Results
A run that produces no JSON output at all fails withstop_reason: invalid_output rather than returning something
unparsable.
Ungroundable fields come back null in output.structured. This is the same “don’t guess” contract
Answer follows.
Next steps
- Basic run: the full request/response cycle, including the cURL poll
- Handle errors: rejected requests versus failed runs
- Reference: endpoints, fields, limits and errors
- Agent API Reference: full
output_schemarequest and response specification