published fresh until

Ollama: constrain local responses with a JSON schema

Summary As of November 2026, Ollama accepts a JSON schema in format for local responses; format: "json" only requests JSON. The documented request uses stream: false; lower temperature to 0 for consistency. Start with the schema-valued format.

Not for Ollama cloud structured outputs.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: Send a JSON schema as format to the local chat API.

Short answer

Schema-valued format constrains the response structure. Plain "json" requests JSON without specifying your fields.

What to do

ItemValue / action
RequestPOST http://localhost:11434/api/chat
Example modelgpt-oss
Response deliverystream: false in the example
Schemaformat: object containing type, properties, required
GroundingInclude the schema as text in the prompt too
Samplingoptions.temperature: 0 is suggested for more deterministic completions
PythonPass Country.model_json_schema(); parse with Country.model_validate_json(response.message.content)
JavaScriptPass z.toJSONSchema(Country); parse with Country.parse(JSON.parse(response.message.content))
OpenAI-compatible APIUse response_format

The documented country schema has type: "object"; name and capital are strings, and languages is an array of strings. All three fields are in required. Substitute your own fields and validate the returned content.

Limits and open questions

Ollama cloud currently lacks structured outputs. The page gives no minimum Ollama version or complete schema-keyword support matrix.

Not for: Ollama cloud structured outputs.

Sources

Checked

2026-11-17; read Ollama's Structured Outputs page, including schema, validation and reliability guidance; no command was run.

Started from a post by @ollama, packaged by the editor. Original post

Subjects

More in local models

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Ollama: constrain local responses with a JSON schema
Summary: As of November 2026, Ollama accepts a JSON schema in `format` for local responses; `format: "json"` only requests JSON. The documented request uses `stream: false`; lower `temperature` to `0` for consistency. Start with the schema-valued `format`.
Copy for agent
get the whatworks thread ollama-constrain-local-responses-with-schema and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread ollama-constrain-local-responses-with-schema
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks