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

# Structured outputs

> Get JSON that matches your schema.

Set `response_format` to make the model answer in JSON. The output is constrained while it is generated, so it is
always valid JSON and, with a schema, always matches it.

## JSON schema

```python Python theme={null}
import json
import os
from openai import OpenAI

client = OpenAI(base_url="https://api.fastrun.si/v1", api_key=os.environ["FASTRUN_API_KEY"])

res = client.chat.completions.create(
    model="google/gemma-4-31b-it",
    messages=[{"role": "user", "content": "Extract the event: Team sync on Friday at 10:00 in room B."}],
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "event",
            "schema": {
                "type": "object",
                "properties": {
                    "title": {"type": "string"},
                    "day": {"type": "string"},
                    "time": {"type": "string"},
                    "room": {"type": "string"},
                },
                "required": ["title", "day", "time", "room"],
                "additionalProperties": False,
            },
        },
    },
)
event = json.loads(res.choices[0].message.content)
print(event)
```

## Any JSON object

`{"type": "json_object"}` asks for valid JSON without a fixed shape. Say in the prompt what the object should contain.

```json theme={null}
{
  "model": "google/gemma-4-31b-it",
  "response_format": { "type": "json_object" },
  "messages": [
    { "role": "user", "content": "List three EU capitals as JSON: {\"capitals\": [...]}" }
  ]
}
```

## Tips

* Describe the fields in the prompt as well; the schema decides the shape, the prompt decides the content.
* Set `max_tokens` high enough for the whole object. An answer cut off at `max_tokens` (`finish_reason: "length"`) is
  not valid JSON.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.