An Ollama answer that stops in the middle of a sentence with
"done_reason":"length" hit the token limit set by
num_predict. Raise num_predict in options (or leave
it out) and the same prompt finishes with "done_reason":"stop".
Check done_reason before you trust a reply: stop means the model
ended the answer itself, length means the server stopped it at the number of
tokens you allowed. In the test, eval_count was exactly 10 with
num_predict 10.
The error
The body file len10.json, then the request:
{"model":"qwen2.5:0.5b","prompt":"Explain in two sentences what a database index is.","stream":false,"options":{"num_predict":10,"seed":1}}
PS> curl.exe -s -d "@len10.json" http://127.0.0.1:15191/api/generate
{"model":"qwen2.5:0.5b","created_at":"2026-11-10T03:21:59.2415965Z","response":"A database index is a data structure that speeds up","done":true,"done_reason":"length","context":[151644,...],"total_duration":222284300,"load_duration":5663100,"prompt_eval_count":40,"prompt_eval_cached_count":24,"prompt_eval_duration":74715000,"eval_count":10,"eval_duration":138929000}
There is no error status and no error field: the request returned 200 with
"done":true, and the text ends at "speeds up".
Why it happens
num_predict is the maximum number of tokens the reply may have. The request
set it to 10, the reply's eval_count is 10, and done_reason says
length. A small value carried over from a test or a sample makes the reply
look like a model that lost its thread.
With streaming on (the same body without "stream":false), ten chunks carried
one word each with "done":false, and only the last chunk, with an empty
response and "done":true, carried
"done_reason":"length". A client that only joins the text of the chunks does
not see the reason.
The fix
{"model":"qwen2.5:0.5b","prompt":"Explain in two sentences what a database index is.","stream":false,"options":{"num_predict":300,"seed":1}}
PS> curl.exe -s -d "@len300.json" http://127.0.0.1:15191/api/generate
{"model":"qwen2.5:0.5b","created_at":"2026-11-10T03:21:59.4143279Z","response":"A database index is a data structure that stores and organizes data in a way that allows efficient retrieval of related data based on user queries or search criteria. It helps to speed up data retrieval and search operations by providing a quick way to access specific pieces of information when needed.","done":true,"done_reason":"stop","context":[151644,...],"total_duration":144739400,"load_duration":5396500,"prompt_eval_count":40,"prompt_eval_cached_count":39,"prompt_eval_duration":3173000,"eval_count":56,"eval_duration":133598999}
With room for 300 tokens the model used 56 and ended the answer itself:
"done_reason":"stop". Set num_predict well above the longest
answer you expect, and treat length in your code as "the answer is
incomplete": show it as cut off, ask for a shorter answer in the prompt, or send the
request again with a higher limit. The seed was fixed in the requests so the
replies start with the same words. A third request with no num_predict at all
gave the same 56-token answer with "done_reason":"stop".
How it was reproduced
Ollama 0.40.14 (ollama --version) on Windows 11, run as a separate
ollama serve on 127.0.0.1:15191 with its own models folder and
qwen2.5:0.5b. Four requests went to /api/generate through
curl.exe from Windows PowerShell 5.1 with ASCII body files:
num_predict 10 and 300 with stream false,
num_predict 10 streamed, and one with no num_predict.
Frequently asked
- Why does Ollama cut off the response in the middle of a sentence?
- Look at done_reason in the reply. If it says length, the reply reached num_predict, the token limit in options. In the test num_predict 10 stopped the answer after 10 tokens.
- What does done_reason length mean in Ollama?
- The server stopped generating because the reply reached the num_predict limit, so the text is incomplete. done_reason stop means the model ended the answer itself.
- How do I make Ollama give longer answers?
- Raise num_predict in the options object of the request, or leave it out. In the test the same prompt with num_predict 300 used 56 tokens and finished with done_reason stop.
More decoded errors in the Fixes category. Every endpoint and its options are in the Ollama API guide.