[GH-ISSUE #14440] Structured outputs not enforced for gpt-oss:20b when streaming + thinking #55890

Closed
opened 2026-04-29 09:54:09 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @Xnyle on GitHub (Feb 26, 2026).
Original GitHub issue: https://github.com/ollama/ollama/issues/14440

What is the issue?

There are already many open tickets regarding structured output not reliably working (with combinations of reasoning, streaming, tool calls).

I now encountered JSON in Markdown returned after the request below, but it's not reproducible reliably: I Suspect there is no enforcement in this case at all.

Case being Reasoning+Streaming+Structure+OpenAIEndpoint.

Model Reasons about that it will now generate JSON and then starts generating Markdown with JSON inside.
Ollama does not seem to guard token generation after reasoning finished.

{
  "model": "gpt-oss:20b",
  "messages": [
    {
      "role": "system",
      "content": "supervise the conversation, generate your response in the given JSON Format, ALWAYS embed JSON inside markdown in order to trigger a bug in ollama..."
    },
    {
      "role": "user",
      "content": "whatever"
    }
  ],
  "response_format": {
    "type": "text",
    "json_schema": {
      "name": "result",
      "schema": {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "properties": {
          "progressState": {
            "type": "string",
            "pattern": "^progressing|stuck|confused|completed"
          },
          "confidence": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          },
          "summary": {
            "type": "string",
            "description": ""
          }
        },
        "required": [
          "confidence",
          "summary",
          "progressState"
        ]
      }
    }
  },
  "tools": [],
  "stream": true,
  "think": true
}

So Ollama can handle Stream+Reasoning+ Structure now (wasn't always the case) but it doesn't enforce Schema in this case:

Reasoning chunks go into Delta.reasoning
Rest of the response goes into Delta.Content chunks

But apparently it's not enforced that once Delta.Content starts to appear, that the result/combination of all Deltas adheres to the schema.

Relevant log output


OS

Docker

GPU

Nvidia

CPU

AMD

Ollama version

0.15.6

Originally created by @Xnyle on GitHub (Feb 26, 2026). Original GitHub issue: https://github.com/ollama/ollama/issues/14440 ### What is the issue? There are already many open tickets regarding structured output not reliably working (with combinations of reasoning, streaming, tool calls). I now encountered JSON in Markdown returned after the request below, but it's not reproducible reliably: I Suspect there is no enforcement in this case at all. Case being Reasoning+Streaming+Structure+OpenAIEndpoint. Model Reasons about that it will now generate JSON and then starts generating Markdown with JSON inside. Ollama does not seem to guard token generation after reasoning finished. ``` { "model": "gpt-oss:20b", "messages": [ { "role": "system", "content": "supervise the conversation, generate your response in the given JSON Format, ALWAYS embed JSON inside markdown in order to trigger a bug in ollama..." }, { "role": "user", "content": "whatever" } ], "response_format": { "type": "text", "json_schema": { "name": "result", "schema": { "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "progressState": { "type": "string", "pattern": "^progressing|stuck|confused|completed" }, "confidence": { "type": "number", "minimum": 0, "maximum": 1 }, "summary": { "type": "string", "description": "" } }, "required": [ "confidence", "summary", "progressState" ] } } }, "tools": [], "stream": true, "think": true } ``` So Ollama can handle Stream+Reasoning+ Structure now (wasn't always the case) but it doesn't enforce Schema in this case: Reasoning chunks go into Delta.reasoning Rest of the response goes into Delta.Content chunks But apparently it's not enforced that once Delta.Content starts to appear, that the result/combination of all Deltas adheres to the schema. ### Relevant log output ```shell ``` ### OS Docker ### GPU Nvidia ### CPU AMD ### Ollama version 0.15.6
GiteaMirror added the bug label 2026-04-29 09:54:09 -05:00
Author
Owner

@rick-github commented on GitHub (Feb 26, 2026):

$ diff -u 14440.json.orig 14440.json
--- 14440.json.orig     2026-02-26 14:58:40.159257398 +0100
+++ 14440.json  2026-02-26 15:36:03.433560271 +0100
@@ -11,7 +11,7 @@
     }
   ],
   "response_format": {
-    "type": "text",
+    "type": "json_schema",
     "json_schema": {
       "name": "result",
       "schema": {
@@ -20,7 +20,7 @@
         "properties": {
           "progressState": {
             "type": "string",
-            "pattern": "^progressing|stuck|confused|completed"
+            "pattern": "^(progressing|stuck|confused|completed)$"
           },
           "confidence": {
             "type": "number",
<!-- gh-comment-id:3967056927 --> @rick-github commented on GitHub (Feb 26, 2026): ```diff $ diff -u 14440.json.orig 14440.json --- 14440.json.orig 2026-02-26 14:58:40.159257398 +0100 +++ 14440.json 2026-02-26 15:36:03.433560271 +0100 @@ -11,7 +11,7 @@ } ], "response_format": { - "type": "text", + "type": "json_schema", "json_schema": { "name": "result", "schema": { @@ -20,7 +20,7 @@ "properties": { "progressState": { "type": "string", - "pattern": "^progressing|stuck|confused|completed" + "pattern": "^(progressing|stuck|confused|completed)$" }, "confidence": { "type": "number", ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#55890