[GH-ISSUE #7603] API: JSON response is empty #4851

Closed
opened 2026-04-12 15:50:55 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @boessu on GitHub (Nov 10, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/7603

What is the issue?

Hello

I'm not sure if that is a model specific problem, but sometimes I get a (somewhat) empty JSON response. It doesn't happen if the format is not set to json.

Example:

C:\Users\Boessu>curl http://localhost:11434/api/generate -d "{\"model\":\"llama3.2\",\"prompt\":\"Why is the sky blue?\",\"stream\":false,\"format\":\"json\"}"
{"model":"llama3.2","created_at":"2024-11-10T19:30:29.9494461Z","response":"{}\n \n \n\n\n\n\n\n  \n\n\n\n \n \n\n\n\n\n\n\n  \n\n\n\n \n\n  \n \n\n\n \n  \n\n\n\n\n\n\n\n\n\n\n     \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n      \n \n\n\n\n \n \n \n\n\n\n\n      \n\n\n\n\n\n\n\n\n\n\n\n \n  \n  \n \n \n \n \n  \n ","done":false}

If I retry that request several times, I get the answer in the JSON response after some time. The "empty" response is also quite fast (quite frankly too fast, as it has to load the model...).

It "normally" happens if ollama has to load the model with the request. So to reproduce you should execute "ollama stop llama3.2" before.

Maybe it has to do with the loading of the model?

OS

Windows

GPU

AMD

CPU

AMD

Ollama version

0.4.0

Originally created by @boessu on GitHub (Nov 10, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/7603 ### What is the issue? Hello I'm not sure if that is a model specific problem, but sometimes I get a (somewhat) empty JSON response. It doesn't happen if the format is not set to json. Example: ``` C:\Users\Boessu>curl http://localhost:11434/api/generate -d "{\"model\":\"llama3.2\",\"prompt\":\"Why is the sky blue?\",\"stream\":false,\"format\":\"json\"}" {"model":"llama3.2","created_at":"2024-11-10T19:30:29.9494461Z","response":"{}\n \n \n\n\n\n\n\n \n\n\n\n \n \n\n\n\n\n\n\n \n\n\n\n \n\n \n \n\n\n \n \n\n\n\n\n\n\n\n\n\n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n \n\n\n\n \n \n \n\n\n\n\n \n\n\n\n\n\n\n\n\n\n\n\n \n \n \n \n \n \n \n \n ","done":false} ``` If I retry that request several times, I get the answer in the JSON response after some time. The "empty" response is also quite fast (quite frankly too fast, as it has to load the model...). It "normally" happens if ollama has to load the model with the request. So to reproduce you should execute "ollama stop llama3.2" before. Maybe it has to do with the loading of the model? ### OS Windows ### GPU AMD ### CPU AMD ### Ollama version 0.4.0
GiteaMirror added the bug label 2026-04-12 15:50:55 -05:00
Author
Owner

@rick-github commented on GitHub (Nov 10, 2024):

If you send a prompt with "format":"json", you get better results if you also include in the prompt that you want JSON. If you don't, models start spitting out tons of whitespace, which triggers the dupe detection in ollama and the output is cut short: notice that done is false, because of this truncation.

 $ curl http://localhost:11434/api/generate -d "{\"model\":\"llama3.2\",\"prompt\":\"Why is the sky blue?  Answer with a JSON object.\",\"stream\":false,\"format\":\"json\"}"
{"model":"llama3.2","created_at":"2024-11-10T21:19:25.975909509Z","response":"{\"question\": \"Why is the sky blue?\", \n \"answer\": \"The sky appears blue because of a phenomenon called Rayleigh scattering, named after the British physicist Lord Rayleigh, who first described it in the late 19th century.\\n\\nIn this process, shorter (blue) wavelengths of light are scattered more than longer (red) wavelengths by the tiny molecules of gases such as nitrogen and oxygen in the Earth's atmosphere. As a result, our eyes see more blue light coming from all directions, giving the sky its characteristic color.\",\n \"additional_info\": \"The exact shade of blue can vary depending on atmospheric conditions, such as dust, pollution, and water vapor content.\"}","done":true,"done_reason":"stop","context":[128006,9125,128007,271,38766,1303,33025,2696,25,6790,220,2366,18,271,128009,128006,882,128007,271,10445,374,279,13180,6437,30,220,22559,449,264,4823,1665,13,128009,128006,78191,128007,271,5018,7998,794,330,10445,374,279,13180,6437,32111,720,330,9399,794,330,791,13180,8111,6437,1606,315,264,25885,2663,13558,64069,72916,11,7086,1306,279,8013,83323,10425,13558,64069,11,889,1176,7633,433,304,279,3389,220,777,339,9478,7255,77,1734,644,420,1920,11,24210,320,12481,8,93959,315,3177,527,38067,810,1109,5129,320,1171,8,93959,555,279,13987,35715,315,45612,1778,439,47503,323,24463,304,279,9420,596,16975,13,1666,264,1121,11,1057,6548,1518,810,6437,3177,5108,505,682,18445,11,7231,279,13180,1202,29683,1933,10560,330,36599,3186,794,330,791,4839,28601,315,6437,649,13592,11911,389,45475,4787,11,1778,439,16174,11,25793,11,323,3090,38752,2262,1210,92],"total_duration":19652350548,"load_duration":18578385361,"prompt_eval_count":38,"prompt_eval_duration":64000000,"eval_count":140,"eval_duration":1008000000}
<!-- gh-comment-id:2466922524 --> @rick-github commented on GitHub (Nov 10, 2024): If you send a prompt with `"format":"json"`, you get better results if you also include in the prompt that you want JSON. If you don't, models start spitting out tons of whitespace, which triggers the dupe detection in ollama and the output is cut short: notice that `done` is `false`, because of this truncation. ```console $ curl http://localhost:11434/api/generate -d "{\"model\":\"llama3.2\",\"prompt\":\"Why is the sky blue? Answer with a JSON object.\",\"stream\":false,\"format\":\"json\"}" {"model":"llama3.2","created_at":"2024-11-10T21:19:25.975909509Z","response":"{\"question\": \"Why is the sky blue?\", \n \"answer\": \"The sky appears blue because of a phenomenon called Rayleigh scattering, named after the British physicist Lord Rayleigh, who first described it in the late 19th century.\\n\\nIn this process, shorter (blue) wavelengths of light are scattered more than longer (red) wavelengths by the tiny molecules of gases such as nitrogen and oxygen in the Earth's atmosphere. As a result, our eyes see more blue light coming from all directions, giving the sky its characteristic color.\",\n \"additional_info\": \"The exact shade of blue can vary depending on atmospheric conditions, such as dust, pollution, and water vapor content.\"}","done":true,"done_reason":"stop","context":[128006,9125,128007,271,38766,1303,33025,2696,25,6790,220,2366,18,271,128009,128006,882,128007,271,10445,374,279,13180,6437,30,220,22559,449,264,4823,1665,13,128009,128006,78191,128007,271,5018,7998,794,330,10445,374,279,13180,6437,32111,720,330,9399,794,330,791,13180,8111,6437,1606,315,264,25885,2663,13558,64069,72916,11,7086,1306,279,8013,83323,10425,13558,64069,11,889,1176,7633,433,304,279,3389,220,777,339,9478,7255,77,1734,644,420,1920,11,24210,320,12481,8,93959,315,3177,527,38067,810,1109,5129,320,1171,8,93959,555,279,13987,35715,315,45612,1778,439,47503,323,24463,304,279,9420,596,16975,13,1666,264,1121,11,1057,6548,1518,810,6437,3177,5108,505,682,18445,11,7231,279,13180,1202,29683,1933,10560,330,36599,3186,794,330,791,4839,28601,315,6437,649,13592,11911,389,45475,4787,11,1778,439,16174,11,25793,11,323,3090,38752,2262,1210,92],"total_duration":19652350548,"load_duration":18578385361,"prompt_eval_count":38,"prompt_eval_duration":64000000,"eval_count":140,"eval_duration":1008000000} ```
Author
Owner

@boessu commented on GitHub (Nov 11, 2024):

Hello @rick-github

Thanks for the tip. That seems to fix the problem. At least, I can't reproduce it anymore with this sentence in the prompt.
This behavior is a bit strange, as I've got it on qwen2.5 too.

Anyhow. I should close this issue. That was helpful. Thanks.

Cheers

<!-- gh-comment-id:2468784464 --> @boessu commented on GitHub (Nov 11, 2024): Hello @rick-github Thanks for the tip. That seems to fix the problem. At least, I can't reproduce it anymore with this sentence in the prompt. This behavior is a bit strange, as I've got it on qwen2.5 too. Anyhow. I should close this issue. That was helpful. Thanks. Cheers
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#4851