Structured output means the model returns data in a fixed shape, such as JSON with named fields, instead of free text. Ollama 0.11.0 added structured outputs for gpt-oss models, and other runtimes offer the same idea through a schema. A schema only helps if you validate the reply against it, because a model can still return invalid JSON.
Checked on 2026-11-29. We did not run any tool for this guide. Every result below is an expected result, marked UNTESTED, for you to confirm on your own files.
Prerequisites
- A model or runtime that supports structured output
- A JSON schema for the fields you need
- A validator, such as a small script or an online JSON schema checker used locally
Steps
1. Write the schema first
Define each field, its type and whether it is required. Keep it to the fields you actually need.
Expected result: A schema exists with named fields, types and required flags.
2. Ask for the schema in the prompt
Send the schema with the request and ask for JSON only, with no extra text around it.
Expected result: The request contains the schema and asks for JSON only.
3. Validate the reply
Parse the reply as JSON, then check it against the schema. Record any missing field or wrong type.
Expected result: The reply is marked valid or invalid, with each failure named.
4. Handle the invalid case
If the reply is invalid, retry once with the same schema, and if it still fails, fall back to a safe default instead of guessing.
Expected result: A retry and fallback path exists and is written down before the code ships.
Worked example
A practice schema asks for a meeting summary with three fields. One reply missed a field and failed validation.
| Field | Type | Reply value |
|---|---|---|
| date | string | 2026-11-29 |
| decisions | array | 2 items |
| owner | string | missing |
Expected result: Two fields validate and one fails, so the reply is marked invalid and retried once (UNTESTED – confirm it yourself.)
Verdict table
| Check | Expected result | Pass? |
|---|---|---|
| Write the schema first | A schema exists with named fields, types and required flags. | – |
| Ask for the schema in the prompt | The request contains the schema and asks for JSON only. | – |
| Validate the reply | The reply is marked valid or invalid, with each failure named. | – |
| Handle the invalid case | A retry and fallback path exists and is written down before the code ships. | – |
Limits
- A valid schema does not mean the values are true; validate facts against the source separately.
- Not every model supports structured output; check the model docs first.
Sources
- Ollama v0.12.6 release notes – checked 2026-11-29
- Ollama v0.12.10 release notes – checked 2026-11-29
- Ollama v0.11.0 release notes – checked 2026-11-29
