> ## Documentation Index
> Fetch the complete documentation index at: https://developers.datagrid.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Structured Outputs

> Ensure responses adhere to a JSON schema.

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](https://json-schema.org/overview/what-is-jsonschema). 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.

<CodeGroup>
  ```python Python theme={null}
  from datagrid_ai import Datagrid
  import json

  datagrid = Datagrid()

  example_json_schema = {
      "type": "object",
      "properties": {
          "name": {
              "type": "string",
              "description": "The name of the movie"
          },
          "director": {
              "type": "string",
              "description": "The director of the movie"
          },
          "release_year": {
              "type": "number",
              "description": "The year the movie was released"
          }
      },
      "required": ["name", "director", "release_year"],
      "additionalProperties": False
  }

  response = datagrid.converse(
      prompt="What movie won best picture at the 2001 Oscars?",
      text={"format": example_json_schema}
  )

  # Example response: '{ "name": "Gladiator", "director": "Ridley Scott", "release_year": 2000 }'
  structured_response = json.loads(response["content"][0]["text"])
  ```

  ```javascript JavaScript theme={null}
  import Datagrid from "datagrid-ai";

  const datagrid = new Datagrid();

  const movieJsonSchema = {
      type: "object",
      properties: {
          name: {
              type: "string",
              description: "The name of the movie",
          },
          director: {
              type: "string",
              description: "The director of the movie",
          },
          release_year: {
              type: "number",
              description: "The year the movie was released",
          },
      },
      required: ["name", "director", "release_year"],
      additionalProperties: false,
  };

  const response = await datagrid.converse({
      prompt: "What movie won best picture at the 2001 Oscars?",
      text: { format: movieJsonSchema },
  });

  // Example response: "{ "name": "Gladiator", "director": "Ridley Scott", "release_year": 2000 }"
  const structuredResponse = JSON.parse(response.content[0].text);
  ```
</CodeGroup>

Libraries such as [Pydantic](https://pypi.org/project/pydantic/) (Python) or [Zod](https://www.npmjs.com/package/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](./modes) for how **Ask** (`llm_router`), **Extended**, **Execute**, and **`llm-only`** differ for tools and latency.
