[GH-ISSUE #13184] Formatted Outputs's Schemas #8716

Closed
opened 2026-04-12 21:29:13 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @KansaiUser on GitHub (Nov 21, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/13184

I would like to ask for clarification about Structured Outputs (here in the docs)

It is written

Structured outputs
Structured outputs are supported by providing a JSON schema in the format parameter. The model will generate a response that matches the schema. See the Chat request (Structured outputs) example below.

And then we have an example in

Chat request (Structured outputs)
Request

curl -X POST http://localhost:11434/api/chat -H "Content-Type: application/json" -d '{
  "model": "llama3.1",
  "messages": [{"role": "user", "content": "Ollama is 22 years old and busy saving the world. Return a JSON object with the age and availability."}],
  "stream": false,
  "format": {
    "type": "object",
    "properties": {
      "age": {
        "type": "integer"
      },
      "available": {
        "type": "boolean"
      }
    },
    "required": [
      "age",
      "available"
    ]
  },
  "options": {
    "temperature": 0
  }
}'

is this schema (type, properties, required) the only one accepted? or is it the one checked and recommended?

Or can the user just provide any type of well formed JSON here? in order for it to work

Note: I have used successfully the schema above, but in my team there is an ongoing discussion if other schemas are possible.

Note: I know that you can just put "format": "json", too, but my question is about schemas

Originally created by @KansaiUser on GitHub (Nov 21, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/13184 I would like to ask for clarification about Structured Outputs (here in the [docs](https://github.com/ollama/ollama/blob/feb18cd710dec1e4754ea56124238a11eb3cb90a/docs/api.md#structured-outputs-1)) It is written > Structured outputs > Structured outputs are supported by providing a JSON schema in the format parameter. The model will generate a response that matches the schema. See the [Chat request (Structured outputs)](https://github.com/ollama/ollama/blob/feb18cd710dec1e4754ea56124238a11eb3cb90a/docs/api.md#chat-request-structured-outputs) example below. And then we have an example in Chat request (Structured outputs) Request ``` curl -X POST http://localhost:11434/api/chat -H "Content-Type: application/json" -d '{ "model": "llama3.1", "messages": [{"role": "user", "content": "Ollama is 22 years old and busy saving the world. Return a JSON object with the age and availability."}], "stream": false, "format": { "type": "object", "properties": { "age": { "type": "integer" }, "available": { "type": "boolean" } }, "required": [ "age", "available" ] }, "options": { "temperature": 0 } }' ``` is this schema (type, properties, required) the only one accepted? or is it the one checked and recommended? Or can the user just provide any type of well formed JSON here? in order for it to work Note: I have used successfully the schema above, but in my team there is an ongoing discussion if other schemas are possible. Note: I know that you can just put ` "format": "json",` too, but my question is about schemas
Author
Owner

@rick-github commented on GitHub (Nov 21, 2025):

Any well-formed JSON will work.

$ curl -s http://localhost:11434/api/chat -d '{
    "model":"qwen2.5:0.5b",
    "messages":[{"role":"user","content":"Give me some random strings"}],
    "format":{
        "items":{"type":"string"},
        "type":"array"
     },
     "stream":false}' | jq -r .message.content
[ "cloud", "hello", "world", "code", "python" ]

There are some caveats: the JSON is converted to a GBNF which has some restrictions, eg patterns must be fully anchored

<!-- gh-comment-id:3563399569 --> @rick-github commented on GitHub (Nov 21, 2025): Any well-formed JSON will work. ```console $ curl -s http://localhost:11434/api/chat -d '{ "model":"qwen2.5:0.5b", "messages":[{"role":"user","content":"Give me some random strings"}], "format":{ "items":{"type":"string"}, "type":"array" }, "stream":false}' | jq -r .message.content [ "cloud", "hello", "world", "code", "python" ] ``` There are some caveats: the JSON is converted to a GBNF which has some restrictions, eg [patterns must be fully anchored](https://github.com/ollama/ollama/issues/12726)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#8716