ollama - 💡(How to fix) Fix structured output not enfocred on qwen 3.5 / gemma 4 [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
ollama/ollama#15540Fetched 2026-04-15 06:20:21
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
closed ×1commented ×1labeled ×1

Error Message

Is this expected / a bug / error in request?

Code Example

{
  "model": "qwen3.5:9b",
  "messages": [
    {
      "id": "ec197bbb-5f8b-4199-a051-c5e01aaadddd",
      "created_at": -2038034357,
      "completed_at": -2038034356,
      "role": "system",
      "content": "Instructions explaining schema and role... ",
      "metadata": {}
    },
    {
      "id": "491b00b9-27c4-444b-a59f-ead4b02190c1",
      "created_at": -2038034351,
      "completed_at": -2038034254,
      "role": "user",
      "content": "Hi ...",
      "metadata": {}
    }
  ],
  "logprobs": false,
  "temperature": 0.7,
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "name": "result",
      "schema": {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "properties": {
          "markdownAnswer": {
            "type": "string"
          },
          "references": {
            "type": "array",
            "items": {
              "$ref": "#/$defs/references"
            },
            "minItems": 1
          }
        },
        "required": [
          "markdownAnswer",
          "references"
        ],
        "$defs": {
          "references": {
            "type": "object",
            "properties": {
              "originIdentifier": {
                "type": "string",
                "pattern": "^[0-9]{1,4}-[0-9]{1,2}$"
              },
              "originMediaType": {
                "type": "string"
              }
            },
            "required": [
              "originIdentifier",
              "originMediaType"
            ]
          }
        }
      }
    }
  },
  "stream": true,
  "reasoning": {
    "effort": "none"
  },
  "stream_options": {
    "include_usage": true
  },
  "reasoning_effort": "none"
}

---
RAW_BUFFERClick to expand / collapse

What is the issue?

Using ollama/ollama:0.20.3 and the request (stripped) below to the OpenAI compatible endpoint Ollama returns deltas that in sum do not obey the given schema for at least Gemma 4 26b and Qwen 3 9b.

Sometimes I get Json in markdown but thats it.

Working fine with Gemma3 / GPT OSS

Is this expected / a bug / error in request?

{
  "model": "qwen3.5:9b",
  "messages": [
    {
      "id": "ec197bbb-5f8b-4199-a051-c5e01aaadddd",
      "created_at": -2038034357,
      "completed_at": -2038034356,
      "role": "system",
      "content": "Instructions explaining schema and role... ",
      "metadata": {}
    },
    {
      "id": "491b00b9-27c4-444b-a59f-ead4b02190c1",
      "created_at": -2038034351,
      "completed_at": -2038034254,
      "role": "user",
      "content": "Hi ...",
      "metadata": {}
    }
  ],
  "logprobs": false,
  "temperature": 0.7,
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "name": "result",
      "schema": {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "properties": {
          "markdownAnswer": {
            "type": "string"
          },
          "references": {
            "type": "array",
            "items": {
              "$ref": "#/$defs/references"
            },
            "minItems": 1
          }
        },
        "required": [
          "markdownAnswer",
          "references"
        ],
        "$defs": {
          "references": {
            "type": "object",
            "properties": {
              "originIdentifier": {
                "type": "string",
                "pattern": "^[0-9]{1,4}-[0-9]{1,2}$"
              },
              "originMediaType": {
                "type": "string"
              }
            },
            "required": [
              "originIdentifier",
              "originMediaType"
            ]
          }
        }
      }
    }
  },
  "stream": true,
  "reasoning": {
    "effort": "none"
  },
  "stream_options": {
    "include_usage": true
  },
  "reasoning_effort": "none"
}

Relevant log output

OS

Docker

GPU

Nvidia

CPU

Intel

Ollama version

0.20.3

extent analysis

TL;DR

The issue may be due to an incompatibility between the provided JSON schema and the Ollama version 0.20.3, causing incorrect deltas in the response.

Guidance

  • Verify that the JSON schema provided is compatible with Ollama version 0.20.3 by checking the documentation for any known issues or limitations.
  • Test the request with a simpler JSON schema to see if the issue persists, which can help determine if the problem is with the schema or the request itself.
  • Compare the behavior with Gemma3 / GPT OSS to identify any differences in how the schema is handled.
  • Check the Ollama documentation for any specific requirements or restrictions on the JSON schema format.

Example

No code snippet is provided as the issue seems to be related to the compatibility of the JSON schema with the Ollama version.

Notes

The issue might be specific to the combination of Ollama version 0.20.3 and the provided JSON schema. Further investigation into the compatibility of the schema with the Ollama version is needed.

Recommendation

Apply workaround: Try simplifying the JSON schema or checking for any updates to the Ollama version that may address compatibility issues with the provided schema.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING