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.
Copy
Ask AI
from datagrid_ai import Datagridimport jsondatagrid = 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 is currently only supported by the default agent model, magpie-1.1.