Skip to main content
JSON is one of the most common formats used for data exchange between applications. Structured Outputs is a feature that guarantees the model’s responses will always match your provided JSON Schema. This means you can rely on it to include all required fields and avoid generating invalid enum values or incorrect formats. You can request Datagrid to output a structured response by passing in a JSON Schema into the text.format field. Structured outputs work for every Converse agent_model and chat_mode when you supply text.format; differences between modes are about tools and routing, not about whether schema-constrained JSON is available.
Libraries such as Pydantic (Python) or Zod (JavaScript) are recommended when manipulating JSON Schemas. Structured output uses the text.format field on the Converse request: you pass a JSON Schema, and the model returns JSON that follows it. Use Modes for how Ask (llm_router), Extended, Execute, and llm-only differ for tools and latency.

Validation and error handling

Structured outputs are enforced server-side. After the agent generates a response, Datagrid validates it against your text.format schema before returning it:
  • On success, the validated value is returned as a json content item with the value already parsed — you don’t need JSON.parse / json.loads. A JSON-string text content item is also returned, so existing integrations that read content[0].text keep working.
  • On failure — when the agent cannot produce schema-valid JSON — Datagrid does not return partial or non-conforming data, and no json content item is included. It returns a deterministic error object in a text content item:
Read the structured result from the json content item (or parse the JSON-string content[0].text), and treat structured_output_generation_failed as a signal to retry the request or relax your schema.