[GH-ISSUE #8543] Ollama does not perform structured output correctly. #31271

Open
opened 2026-04-22 11:35:15 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @Underline-1024 on GitHub (Jan 23, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/8543

What is the issue?

request:
{ "model":"llama3.2", "messages":datas+[ { "role":"user", "content":input_data, "images":[screenshot_base64] } ], "stream":False, "format":{ "type":"object", "reply":{"type":"string"}, "properties":{ "operations":{"type":"array", "instruct":{ "type":"object", "functions":{"type":"object", "function_name":{ "type":"string"}, "parameter":{"type":"array","items":{"type":"string"}} } } } } }, "required":["reply"] }
reply:
{"operations": []}
Ollama did not reply with the required "reply".

OS

Windows

GPU

Nvidia

CPU

Intel

Ollama version

0.5.7

Originally created by @Underline-1024 on GitHub (Jan 23, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/8543 ### What is the issue? request: `{ "model":"llama3.2", "messages":datas+[ { "role":"user", "content":input_data, "images":[screenshot_base64] } ], "stream":False, "format":{ "type":"object", "reply":{"type":"string"}, "properties":{ "operations":{"type":"array", "instruct":{ "type":"object", "functions":{"type":"object", "function_name":{ "type":"string"}, "parameter":{"type":"array","items":{"type":"string"}} } } } } }, "required":["reply"] }` reply: `{"operations": []}` Ollama did not reply with the required "reply". ### OS Windows ### GPU Nvidia ### CPU Intel ### Ollama version 0.5.7
GiteaMirror added the bug label 2026-04-22 11:35:15 -05:00
Author
Owner

@rock-feller commented on GitHub (Jan 27, 2025):

I am not sure why they can not fix it. I am having the same issues. Can't constraint the models to provide a structured output based based on my custom pydantic basemodel as json schema, as explained here

<!-- gh-comment-id:2615201312 --> @rock-feller commented on GitHub (Jan 27, 2025): I am not sure why they can not fix it. I am having the same issues. Can't constraint the models to provide a structured output based based on my custom pydantic basemodel as json schema, as explained [here](https://ollama.com/blog/structured-outputs)
Author
Owner

@mmiscool commented on GitHub (Aug 5, 2025):

I can also confirm that structured outputs are not working.

The example provided at https://ollama.com/blog/structured-outputs is not working at all.
The LLM always responses with a plane string that contains no JSON to be parsed.

import ollama from 'ollama';
import { z } from 'zod';
import { zodToJsonSchema } from 'zod-to-json-schema';

const Country = z.object({
    name: z.string(),
    capital: z.string(), 
    languages: z.array(z.string()),
});

const response = await ollama.chat({
    model: 'llama3.1',
    messages: [{ role: 'user', content: 'Tell me about Canada.' }],
    format: zodToJsonSchema(Country),
});

const country = Country.parse(JSON.parse(response.message.content));
console.log(country);

<!-- gh-comment-id:3153192782 --> @mmiscool commented on GitHub (Aug 5, 2025): I can also confirm that structured outputs are not working. The example provided at https://ollama.com/blog/structured-outputs is not working at all. The LLM always responses with a plane string that contains no JSON to be parsed. ``` import ollama from 'ollama'; import { z } from 'zod'; import { zodToJsonSchema } from 'zod-to-json-schema'; const Country = z.object({ name: z.string(), capital: z.string(), languages: z.array(z.string()), }); const response = await ollama.chat({ model: 'llama3.1', messages: [{ role: 'user', content: 'Tell me about Canada.' }], format: zodToJsonSchema(Country), }); const country = Country.parse(JSON.parse(response.message.content)); console.log(country); ```
Author
Owner

@mmiscool commented on GitHub (Aug 5, 2025):

I was able to get the example code working.
It turns out that you need to use an older version of zod. The zod version 3.X.X version seems to work. The 4.X.X version dose not work.

{
  "name": "testing ollama",
  "version": "1.0.0",
  "type": "module",
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "ollama": "^0.5.16",
    "snipsplicer": "^1.0.17",
    "zod": "^3.24.6",
    "zod-to-json-schema": "^3.24.6"
  },
  "main": "test.js",
  "description": "",
  "devDependencies": {
    "@types/node": "^24.1.0"
  }
}

<!-- gh-comment-id:3153691378 --> @mmiscool commented on GitHub (Aug 5, 2025): I was able to get the example code working. It turns out that you need to use an older version of zod. The zod version 3.X.X version seems to work. The 4.X.X version dose not work. ``` { "name": "testing ollama", "version": "1.0.0", "type": "module", "keywords": [], "author": "", "license": "ISC", "dependencies": { "ollama": "^0.5.16", "snipsplicer": "^1.0.17", "zod": "^3.24.6", "zod-to-json-schema": "^3.24.6" }, "main": "test.js", "description": "", "devDependencies": { "@types/node": "^24.1.0" } } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#31271