Skip to main content

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.

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.
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"])
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.