[GH-ISSUE #7991] {"error":"json: cannot unmarshal object into Go struct field GenerateRequest.format of type string"} #51624

Closed
opened 2026-04-28 20:39:19 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @sandersemmel on GitHub (Dec 7, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/7991

What is the issue?

I'm trying to have the response be a specific type of JSON. It is mentioned in the documentation:
https://github.com/ollama/ollama/blob/main/docs/api.md#request-structured-outputs

curl -X POST http://localhost:11434/api/generate -H "Content-Type: application/json" -d '{                                                                                
  "model": "phi3",       
  "prompt": "Ollama is 22 years old and is busy saving the world. Respond using JSON",
  "stream": false,
  "format": {
    "type": "object",
    "properties": {
      "age": {
        "type": "integer"
      },
      "available": {
        "type": "boolean"
      }
    },
    "required": [
      "age",
      "available"
    ]
  }
}'

Output:

{"error":"json: cannot unmarshal object into Go struct field GenerateRequest.format of type string"}%

I have also tried other models such as 'llama3:8b' but I get the same message.

OS

macOS

GPU

Nvidia

CPU

No response

Ollama version

ollama version is 0.3.13

Originally created by @sandersemmel on GitHub (Dec 7, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/7991 ### What is the issue? I'm trying to have the response be a specific type of JSON. It is mentioned in the documentation: https://github.com/ollama/ollama/blob/main/docs/api.md#request-structured-outputs ``` curl -X POST http://localhost:11434/api/generate -H "Content-Type: application/json" -d '{ "model": "phi3", "prompt": "Ollama is 22 years old and is busy saving the world. Respond using JSON", "stream": false, "format": { "type": "object", "properties": { "age": { "type": "integer" }, "available": { "type": "boolean" } }, "required": [ "age", "available" ] } }' ``` Output: > {"error":"json: cannot unmarshal object into Go struct field GenerateRequest.format of type string"}% I have also tried other models such as 'llama3:8b' but I get the same message. ### OS macOS ### GPU Nvidia ### CPU _No response_ ### Ollama version ollama version is 0.3.13
GiteaMirror added the bug label 2026-04-28 20:39:19 -05:00
Author
Owner

@rick-github commented on GitHub (Dec 8, 2024):

Structured outputs is a feature of 0.5.0 or newer. Upgrade ollama.

<!-- gh-comment-id:2525351932 --> @rick-github commented on GitHub (Dec 8, 2024): Structured outputs is a feature of [0.5.0](https://github.com/ollama/ollama/releases/tag/v0.5.0) or newer. [Upgrade](https://github.com/ollama/ollama/blob/main/docs/faq.md#how-can-i-upgrade-ollama) ollama.
Author
Owner

@jmorganca commented on GitHub (Dec 8, 2024):

Thanks for the issue (and thanks @rick-github!). As mentioned 0.5 is required for structured outputs: https://ollama.com/download

<!-- gh-comment-id:2525376070 --> @jmorganca commented on GitHub (Dec 8, 2024): Thanks for the issue (and thanks @rick-github!). As mentioned 0.5 is required for structured outputs: https://ollama.com/download
Author
Owner

@brauliobo commented on GitHub (Apr 19, 2025):

This might happen due to a version mismatch. ollama should warn on run to induce a restart:

braulio @ chicopc ➜  ~  ollama run qwen2.5  
>>> test
Error: error unmarshalling llm prediction response: json: cannot unmarshal number into Go struct field CompletionResponse.done_reason of type string
braulio @ chicopc ➜  ~  ollama --version
ollama version is 0.6.4
Warning: client version is 0.6.5
braulio @ chicopc ➜  ~  sudo systemctl restart ollama ollama@2
Failed to restart ollama@2.service: Unit ollama@2.service not found.
braulio @ chicopc ➜  ~  ollama run qwen2.5
>>> test
Hello! How can I assist you today? Do you have any specific questions or topics you'd like to discuss?
<!-- gh-comment-id:2816740453 --> @brauliobo commented on GitHub (Apr 19, 2025): This might happen due to a version mismatch. ollama should warn on `run` to induce a restart: ``` braulio @ chicopc ➜ ~ ollama run qwen2.5 >>> test Error: error unmarshalling llm prediction response: json: cannot unmarshal number into Go struct field CompletionResponse.done_reason of type string braulio @ chicopc ➜ ~ ollama --version ollama version is 0.6.4 Warning: client version is 0.6.5 braulio @ chicopc ➜ ~ sudo systemctl restart ollama ollama@2 Failed to restart ollama@2.service: Unit ollama@2.service not found. braulio @ chicopc ➜ ~ ollama run qwen2.5 >>> test Hello! How can I assist you today? Do you have any specific questions or topics you'd like to discuss? ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#51624