Ollama Response Stops Halfway Through? num_predict, Stop Sequences & Client Timeout Diagnosis Guide

Key takeaway
When an Ollama answer stops halfway through, the model has rarely failed: one of three stop rules cut the generation short — the output-token cap, a stop sequence, or the client's own timeout. Three controlled comparisons — the same prompt with the cap raised, the same prompt with the stop list removed, and the same request through a patient client — separate the three rules, and the number that proves the cap case is the token count, not a guess.
Introduction
The connection works. The model loads, it answers, and the first sentences arrive normally. Then, halfway through an answer that is clearly unfinished, the text simply ends — sometimes in the middle of a sentence, sometimes in the middle of a word. There is no error message, no crash, and no out-of-memory report. The answer just stops, as if the model had decided it was done, when the content is plainly not done.
That shape — generation that starts, runs, and then ends early without an error — has a specific cause, and it is not "the model crashed" or "the model is not strong enough". A crash or an out-of-memory error reports itself. A truncation ends cleanly, because a stop rule fired: the model reached a limit that was set before generation began, and generation stopped exactly where the rule said it should. The task is to find which rule fired, because the three rules live in three different places and are fixed in three different ways.
Ollama generation has three independent stop rules. The first is the output-token cap, `num_predict`: the maximum number of tokens one answer may generate. The second is the stop sequence list: a set of strings that end generation the moment the model outputs one of them. The third is the client's own timeout: the client waits only so long for a streamed answer, and then cuts the connection itself, while the server is still generating. Each rule leaves a different fingerprint, and the response carries the evidence — if the response is read as one JSON object instead of a stream.
This guide explains how those three rules work, how to prove which one fired, and how to avoid the mistakes that make the diagnosis look confusing. It is a diagnostic guide for one narrow shape: an Ollama answer that starts normally and stops before it is finished, with no error. If the API cannot be reached at all, if the model loads but runs on the CPU, if the model unloads after a few minutes, or if the run ends with an out-of-memory error, different articles apply, and the boundary section near the end says which ones.
Symptom definition: what counts as this problem
This article covers one narrow shape. All three of the following must be true; if any one is missing, the problem belongs somewhere else.
First, Ollama connects successfully, the model loads successfully, and the answer begins — but it stops halfway through, sometimes in the middle of a sentence, sometimes in the middle of a word. There is no error, no crash, and no out-of-memory report. The answer "finishes by itself" while the content is plainly unfinished.
Second, asking the same question again stops at a place with a pattern, or at no fixed place at all. The pattern is the clue: stopping at the same length every time points at the output-token cap; stopping at the same phrase every time points at a stop sequence; stopping after roughly the same number of seconds every time points at the client timeout.
Third, the decisive evidence is the response itself. When the API is called with `stream: false`, the whole response comes back as one JSON object, and it carries two fields that matter: `done_reason`, which says why generation ended, and `eval_count`, which says how many tokens were generated. Read those fields before guessing why the answer stopped — every diagnosis made without them is a guess.
These three shapes need to be kept apart because each one is measured differently. A connection failure is the API connection-layer route in article #565, in the same batch. A model that loads but runs on the CPU is the `num_gpu` layer-count route in article #556. A model that unloads after a few minutes of idling is the `keep_alive` lifecycle route in article #555. A slow answer that does finish is the context and data route in article #555 test T6 and article #562. Training or inference that ends with an out-of-memory error is the allocator and budget route in articles #552, #553, and #564 — and an out-of-memory error reports itself, while a truncation ends cleanly. This article is about the remaining shape: the generation-parameter layer — the connection works, the model is running, but one of three stop rules cut the answer short.
Five layers of mechanism
Ollama generation has three independent stop rules, and two further layers that look like stop rules but are not. The official API documentation's parameter table and the ssdnodes guide agree on the mechanism, and the details below come from the sources listed at the end of this article.
Layer one: the output-token cap layer — `num_predict`, default 128. This is a main subject of this article. `num_predict` is the maximum number of tokens one answer may generate, counting output tokens only — the prompt is never charged against it. The official parameter table, quoted by LiteLLM, states it plainly: "Maximum number of tokens to predict when generating text. Default: 128, -1 = infinite generation, -2 = fill context." That default and the -1 sentinel are version-dependent: as of October 2026 the Ollama Modelfile reference gives the default as -1 (infinite generation), earlier versions listed -2, and v0.40.11 clamps a negative or oversized cap to 10×`num_ctx` (ssdnodes). A default of 128 tokens is short — a slightly long answer already exceeds it. When the cap is reached, generation stops where it is, sometimes in the middle of a word. Many tools never say which value they are using, so the cap can be active without the reader knowing. The setting can live in three places: the model's Modelfile (`PARAMETER num_predict`), the `options` of each request, or an interactive session's `/set parameter` command — and the value in the request wins over the Modelfile. The evidence for this layer is test T1. Across the whole article library, "num_predict" appears zero times in either language, and the phrases for generated length and response length appear zero times in either language.
Layer two: the stop-sequence layer — the model hits a preset stop string. This is a main subject of this article. `stop` is a list of strings; the moment the model outputs any one of them, generation ends. The stop strings can come from three places: the model's own Modelfile, the `options.stop` of the request, or a chat tool's default stop strings — role markers such as `"AI assistant:"` are a common example. When the model outputs a stop string the reader does not know exists, the answer ends at a place that looks completely innocent. The way to separate this layer is test T2. Across the whole article library, "stop token", "stop sequence", and the Chinese terms for stop sequence and stop string appear zero times in either language.
Layer three: the client-timeout layer — the client stops waiting and cuts the connection itself. This is a main subject of this article. Generation streams back token by token; the client — curl's `--max-time`, a phone app's timeout setting, a web tool's timeout — waits only as long as it is configured to wait, and then cuts the connection. The server is still generating, but the client has stopped waiting. This rule is different from the first two: the first two are the server saying "stop", while this one is the client saying "I will not wait". Only long answers trigger it — a short answer finishes in seconds and never reaches the timeout, while a long answer takes long enough for the client to give up. The way to separate this layer is test T3. Across the whole article library, "timeout" appears in Chinese only in article #126, about the Windows TDR mechanism — a GPU driver timeout reset, which is an entirely different mechanism from an API client timeout. The Chinese terms for connection timeout and request timeout appear zero times in either language.
Layer four: the context layer — `num_ctx` filling up (explicitly excluded, not a test in this article). This is a boundary layer, not a main subject. `num_ctx` is the size of the context window — the prompt plus what has been generated so far, sharing one space. The ssdnodes guide states the distinction plainly: "`num_ctx` is how much the model can read… `num_predict` is how much the model will write." Raising `num_ctx` lets the model read more; it does not let the answer grow longer. More importantly, in the current version of Ollama — reported by ssdnodes as v0.40.11, with context shift on by default for most models — a full window drops older tokens and generation carries on; it does not stop. So a full context window does not cause truncation in the current version, and this article does not present a `num_ctx` comparison as a truncation test. The version number was not independently verified here, so readers should take their own version's behaviour as authoritative — older versions, before context shift, may have behaved differently.
Layer five: the model layer — whether the truncation point follows the model (auxiliary observation, not a main subject). Ask the same prompt with a different model. If the truncation point follows the model — different models stop in different places — the cause points at that model's own Modelfile parameters, its own `num_predict` or its own stop list. If different models stop at the same length or the same phrase, the cause points at the request layer: the `options` the client sends, or the client's timeout. This is deliberately not counted among the three decisive tests: swapping the model is a general isolation technique, from the model-ladder family of article #179, not a variable unique to this article.
The mechanism leads to one key distinction: `num_ctx` is "how much the model reads", and `num_predict` is "how much the model writes". Raising the context window never makes an answer longer. The cap that makes an answer longer is `num_predict`, the list that ends an answer early is `stop`, and the clock that cuts an answer off is the client's timeout.
Reading the evidence: `done_reason` and `eval_count`
Two fields in the response carry the evidence, and they must be read together. `done_reason` says why generation ended. The official API documentation demonstrates the value `"stop"` for a normal finish — and it demonstrates only that value; it does not list every possible value. A secondary source, the ssdnodes guide, reports that hitting the output cap returns `done_reason` set to `"length"`: "When the model reaches the cap, generation stops where it is, sometimes mid-word, and the response comes back with `done_reason` set to `length`." That value is reported by a secondary source, not demonstrated in the official documentation, so this article does not present it as officially documented. The proof that does not depend on which string a version returns is the number: `eval_count`, the count of tokens generated. When `eval_count` is exactly equal to the `num_predict` cap — 128 tokens generated against a cap of 128 — the cap is proven by arithmetic, whatever the reason string says. If the reader's version returns a different string, the number still stands. Call the API with `stream: false` so the whole response comes back as one JSON object, with both fields visible at once.
Two further mechanisms must be stated plainly, because both are commonly blamed for truncations they do not cause. First, a full context window does not truncate in the current version: context shift drops older tokens and generation carries on, as layer four explains. Second, `keep_alive` cannot unload a model in the middle of generation. Article #555 states it directly: "A model answering a request will not be unloaded halfway through; the timer only runs while idle." The official API documentation gives `keep_alive` a default of `5m`, and it controls how long a model stays loaded after a request finishes — not during one. Blaming a mid-answer stop on `keep_alive` is a misconception, and the misconception section takes it apart.
Seven-step diagnosis
- Characterise the shape. Decide which kind of stop it is: stopping at the same length every time (follow T1), stopping at the same phrase every time (follow T2), or stopping after roughly the same number of seconds every time (follow T3). Record the baseline: the model, the prompt, the client (which app, or curl), `done_reason`, and `eval_count`.
- Read the evidence. Call the API once with `stream: false` and read `done_reason` and `eval_count`. A `done_reason` of `"length"` with `eval_count` exactly equal to the cap points at T1; a `done_reason` of `"stop"` with the content plainly unfinished points at T2; a request that never returns, with curl timing out, points at T3.
- Compare the cap. Run the `num_predict` 128 against -1 comparison (T1). If the truncation point moves with the cap, raise `num_predict` — in the Modelfile, or in each request.
- Compare the stop list. Run the stop-list present against absent comparison (T2). If removing the list lets the answer pass the old truncation point, find which string was the cause, and change it in the Modelfile or in the request.
- Compare the client. Run the app against curl with a long timeout (T3). If curl finishes and the app always stops after roughly the same number of seconds, lengthen the app's timeout setting, or change to a client without such a short timeout.
- Compare the model (auxiliary). Ask the same question with a different model. If the truncation point follows the model, check that model's Modelfile parameters with `ollama show --parameters`.
- Stop. If all three tests still do not separate the cause, record six things — `done_reason`, `eval_count`, `num_predict`, the stop list, the client, and the timeout setting — and bring those notes to a check. Do not reinstall Ollama or the model one after another: reinstalling cannot change a generation parameter.
Three decisive tests
Each test changes exactly one variable and records the same two outcomes: where the answer stops, and what `done_reason` and `eval_count` say. Keep the model, the prompt, and the client fixed unless the test itself says to change one of them. Always call the API with `stream: false`, so the whole response comes back as one JSON object.
T1: Output-cap comparison — the same prompt, `num_predict` 128 against -1 (unlimited), watching whether the truncation point moves and reading `done_reason` and `eval_count`
Version note: the 128 default and the -1 (unlimited) sentinel are version-dependent — as of October 2026 the Ollama Modelfile reference gives the default as -1 (infinite generation), earlier versions listed -2, and v0.40.11 clamps a negative or oversized cap to 10×`num_ctx` — so treat the numbers in this test as the parameter-table snapshot cited in the sources, and read the model's own parameters first.
Use curl to call the API directly, with `stream: false`, so the whole response returns at once. Ask the same prompt with the same model twice: first with `options: { "num_predict": 128 }`, then with `options: { "num_predict": -1 }` — or a large number, such as 1024. Record `done_reason` and `eval_count` for each run.
- Variable: the `num_predict` cap.
- Outcome variables: whether the truncation point moves, and what `done_reason` and `eval_count` report.
- If the first run stops with `eval_count` exactly equal to 128 and the second run finishes the answer, the output-cap layer is confirmed. The number is the proof: 128 tokens generated against a cap of 128 leaves no room for doubt. The `done_reason` value reported for the capped run is `"length"` according to the ssdnodes guide — a secondary source, since the official API documentation demonstrates only `"stop"` — so the number, not the string, is what this test relies on.
- If both runs stop at the cap — 128 tokens at a cap of 128, 1024 tokens at a cap of 1024 — the confirmation is even stronger: the truncation point follows the cap.
- Before running the comparison, check which setting wins: the value in the request's `options` wins over the Modelfile's `PARAMETER num_predict`. Run `ollama show --parameters <model>` to see the model's own parameters first, because many models already carry their own cap in the Modelfile, and the "default 128" only applies when nothing is set anywhere.
Why this test is new: "num_predict" appears zero times in either language across the whole article library. Article #555 test T6 varies `num_ctx` and model size, and its outcome is "whether the model stays loaded"; T1's variable is `num_predict` and its outcome is "whether the truncation point moves, and what `done_reason` and `eval_count` report". Article #556's variable is the `num_gpu` layer count, and its outcome is CPU against GPU. Article #179's variable is the quantisation level, and its outcome is "whether the card is big enough before purchase". All three variable sets are different.
T2: Stop-sequence comparison — the same prompt, the stop list present against absent, watching whether the answer can pass the truncation point
First, record the last few words of the first truncated answer — for example, a marker such as `"AI assistant:"` or `"---"`. Then ask the same prompt again, with `options` carrying no `stop` at all — or an empty list — and everything else unchanged.
- Variable: whether the suspected string is in the stop list.
- Outcome variable: whether the answer passes the old truncation point and keeps going.
- If removing the stop list lets the answer pass the old truncation point and continue, the stop-sequence layer is confirmed. To verify in the other direction, add the suspected string explicitly to `stop`: if the answer stops at the same place again, the confirmation is stronger.
- The two kinds of `"stop"` must be told apart: a model that has genuinely finished says `done_reason` `"stop"` with complete content, while a model that hit a stop sequence says `done_reason` `"stop"` with content that is plainly unfinished. The reason string is the same; the content is what separates them.
Why this test is new: "stop token", "stop sequence", and the Chinese terms for stop sequence and stop string appear zero times in either language across the whole article library. No neighbouring article teaches a stop-list comparison. Article #555 discusses `keep_alive` stop conditions — an idle timer, not a generation stop sequence. Article #556 discusses layer counts, not stop strings. T2's variable is "whether the string is in the stop list" and its outcome is "whether the answer passes the truncation point" — no neighbouring article has that variable combination.
T3: Client-timeout comparison — the same request, through the usual app or tool against curl with a long timeout and `stream: false`, watching which one stops first
Ask the same prompt with the same model twice. First, ask through the app or web tool normally used, and record how many seconds pass before it stops, and where it stops. Then ask the same question with `curl --max-time 300 http://localhost:11434/api/generate -d '{... "stream": false ...}'`.
- Variable: which client sends the request.
- Outcome variable: which client stops first, and after how many seconds.
- If curl finishes the answer and the app stops after roughly the same number of seconds every time — for example 30 seconds or 60 seconds — the client-timeout layer is confirmed. Lengthen the app's timeout setting, or change to a client without such a short timeout.
- If short questions work in both clients and only long questions fail in the app, the confirmation is stronger: a timeout only bites a long generation, never a short one.
- Note that with `stream: false`, curl waits for the whole response before returning anything, showing no tokens as they arrive. That is exactly what this test needs: the question is whether the client can wait for the whole response.
Why this test is new: "timeout" appears in Chinese only in article #126, about the Windows TDR mechanism — Timeout Detection and Recovery, a GPU driver timeout reset — which is an entirely different mechanism from an API client timeout. No neighbouring article teaches an "app against curl" timeout comparison. T3's variable is "which client sends the request" and its outcome is "which client stops first, and after how many seconds".
Explicitly excluded comparisons
Two comparisons are deliberately not counted among the three decisive tests, because each one is either the wrong variable or a refuted cause.
T4 (excluded): the `num_ctx` truncation comparison. The variable `num_ctx` belongs to article #555 test T6, and the same variable is not counted twice. More importantly, the behaviour is wrong in the current version: with context shift on by default, a full window drops older tokens and generation carries on — it does not stop. Running this comparison cannot point at a truncation, so this article states the point and does not present `num_ctx` as a truncation cause.
T5 (excluded): the `keep_alive` mid-generation unload. Article #555 states directly that a model answering a request will not be unloaded halfway through, and that the timer only runs while idle. `keep_alive` controls how long a model stays loaded after a request finishes. Blaming a truncation on `keep_alive` is wrong, and this article takes it apart in the misconception section rather than presenting it as a cause.
Auxiliary observation: the model-swap comparison (layer five). Ask the same prompt with a different model. If the truncation point follows the model, check that model's Modelfile parameters with `ollama show --parameters`. This is a general isolation technique, not a variable unique to this article, so it is not counted among the three tests.
The three tests, in one table
| Test | Variable changed | Outcome variables | What a positive result means |
|---|---|---|---|
| T1: `num_predict` 128 vs -1 | Output-token cap | Truncation point moves or not; `done_reason`; `eval_count` | Output cap is the cause; `eval_count` equals the cap |
| T2: stop list present vs absent | Whether the string is in the stop list | Answer passes the truncation point or not | Stop sequence is the cause |
| T3: app vs curl, long timeout | Which client sends the request | Which client stops first; after how many seconds | Client timeout is the cause |
| T4 (excluded): `num_ctx` | Context window size | — | Full window drops old tokens and continues in the current version; not a truncation cause |
| T5 (excluded): `keep_alive` | Idle unload timing | — | Model answering a request is never unloaded mid-generation; refuted by #555 |
| Auxiliary: different model, same prompt | Model | Truncation point follows the model or not | Points at the model's own Modelfile parameters |
Common misconceptions
- "The answer stopped, so the model crashed or ran out of memory." Wrong. A crash or an out-of-memory error reports itself. A truncation ends cleanly, because a stop rule fired. Read `done_reason` and `eval_count` first: a token count exactly equal to the cap is the output cap, and a clean stop with unfinished content is a stop sequence.
- "Raising num_ctx will make the answer longer." Wrong. `num_ctx` is "how much the model reads" and `num_predict` is "how much the model writes". Raising the context window lets the model read more; it never makes the answer longer. The setting that makes an answer longer is `num_predict`. The ssdnodes guide states this distinction directly.
- "keep_alive unloaded the model, so the answer stopped halfway." Wrong. Article #555 states directly that a model answering a request will not be unloaded halfway through, and that the timer only runs while idle. `keep_alive` controls how long a model stays loaded after a request finishes.
- "The context window filled up, so the answer was cut off." Wrong in the current version. Ollama's current version has context shift on by default for most models, so a full window drops older tokens and generation carries on. Blaming a truncation on a full context window is wrong in the current version — and readers on an older version should take their own version's behaviour as authoritative.
- "Temperature made the answer stop." Wrong. Temperature controls randomness — how varied the answer is — not when it stops. A high temperature does not make an answer shorter. The stop rules decide when an answer ends. Temperature and answer quality belong to a different article (backup item GF14).
- "Short questions work and long questions stop, so the model is not strong enough." Wrong. Short questions working and long questions stopping is exactly the signature of a cap or a timeout: a short answer never reaches a 128-token cap, and never reaches a 30-second timeout. Do not blame the model first. Run T1 and T3.
Boundary cases: what this article is not
| Situation | Which route applies | Why it is not this article |
|---|---|---|
| Cannot connect to the Ollama API (localhost:11434 has no response) | #565 (this batch) | Connection layer — truncation only happens after the connection works |
| Model loads but runs on the CPU, graphics card idle | #556 | `num_gpu` layer count, not a generation parameter |
| Model unloads after a few minutes, every question reloads it | #555 | `keep_alive` lifecycle, not a generation parameter |
| Answer is slow, but it does finish | #555 T6 / #562 | Speed layer (context and data), not a stop rule |
| Training or inference ends with out of memory | #552 / #553 / #564 | Memory layer — out of memory reports an error, it does not stop quietly |
| Answer quality is poor, rambling, or repetitive | Backup item GF14 (temperature) | Quality layer, not a stop rule |
| Model cannot load at all | #552 | Allocator layer |
| Truncation through the OpenAI-compatible endpoint (/v1/chat/completions) | See the honesty-gaps section | That endpoint uses `max_tokens`, not `num_predict` — this article covers the native API only |
Neighbour articles and the boundary map
This article is #566, and its companion in the same batch is #565, which covers an Ollama API that cannot be reached at all. The two share a batch and a diagnostic style — five layers, seven steps, decisive tests — but nothing else: one is the API connection layer, the other is the generation-parameter layer, and they share no test, no variable, and no outcome. A connection failure happens before generation starts; a truncation happens only after the connection has already worked.
The closest neighbours, read closely. Article #555 is the Ollama lifecycle article. Its test T6 varies model size and `num_ctx` and measures whether a model stays loaded; this article's test T1 varies `num_predict` and measures whether the truncation point moves and what `done_reason` and `eval_count` report. Article #555 also states directly that a model answering a request will not be unloaded halfway through — the sentence that excludes `keep_alive` as a truncation cause. Article #555 contains zero occurrences of "num_predict", "stop token", and the Chinese terms for stop sequence. Article #556 is the Ollama-on-CPU article: `num_gpu` in three settings, the PROCESSOR column of `ollama ps`, and a layer-count against speed gradient — none of its variables is a generation parameter, and it contains zero occurrences of "num_predict", "stop token" and "stop sequence". Article #561 is the faster-whisper article: device, compute type, and model size — inference-tool settings, not Ollama generation parameters. Article #562 is the training-data article: `num_workers`, data placement, and waiting time, with zero occurrences of "num_predict" and "stop sequence". Articles #552, #553, and #564 are the out-of-memory articles: the PyTorch allocator, the vLLM budget, and the LoRA training pools. An out-of-memory error reports itself; a truncation ends with `done: true` — the shape itself separates them. Article #179 is the local-AI memory-planning article: quantisation levels and sizing a card before purchase, with zero occurrences of "num_predict".
The library scan. Across the whole article library, "num_predict" appears zero times in Chinese and zero times in English; "stop token", "stop sequence", and the Chinese terms for stop sequence and stop string appear zero times in both languages; no article covers an Ollama answer stopping halfway, a generation being interrupted, or a response being truncated; "timeout" appears in Chinese only in article #126, about the Windows TDR mechanism; the Chinese terms for connection timeout and request timeout appear zero times in both languages; no article presents a full context window as a truncation cause, and the phrases for generated length, response length, and output length appear zero times in both languages.
Sources and honesty gaps
The facts in this article come from the following sources, checked by search on 2026-11-23: the Ollama official API documentation, at https://github.com/ollama/ollama/blob/main/docs/api.md, for the `/api/generate` parameters, for `keep_alive` defaulting to `5m`, for `stream: false` returning the whole response at once, for the response example demonstrating `done_reason: "stop"` for a normal finish, and for `options` accepting Modelfile parameters such as `temperature`; the LiteLLM quotation of the official API parameter table, at https://raw.githubusercontent.com/BerriAI/litellm/884376644d463a1fc05c846e61c361ff1369a1cc/litellm/llms/ollama/completion/transformation.py, for `num_predict` ("Maximum number of tokens to predict when generating text. Default: 128, -1 = infinite generation, -2 = fill context"), for `stop` ("Sets the stop sequences to use"), and for `num_ctx` ("Sets the size of the context window used to generate the next token. Default: 2048"); the ssdnodes guide "Ollama num_predict: cap the output length", at https://www.ssdnodes.com/learn/ollama-num-predict-explained, for the statement that `num_predict` caps how many tokens a model may generate in one response and counts output tokens only, for the statement that reaching the cap stops generation where it is, sometimes mid-word, with `done_reason` set to `"length"`, for the distinction that `num_ctx` is how much the model can read while `num_predict` is how much it will write, for the statement that context shift is on by default in the current version so a full window drops older tokens and generation carries on, and for the three setting locations — Modelfile, each request's `options`, and the interactive session's `/set parameter` — with the request's value winning; and the linuxprofessional guide "Ollama REST API Reference", at https://linuxprofessional.ie/article.php?slug=ollama-rest-api-reference-linux, for a complete `/api/generate` parameter example with `options` carrying `num_predict: 500`, `stop: ["---", "END"]`, and `keep_alive: "5m"`, and for `curl http://localhost:11434/api/version` as a server check.
Three honesty gaps must be stated plainly. First, there was no local reproduction: no Ollama model was run on a local machine for this article, so the `done_reason` value for a capped run, the context-shift behaviour, and `eval_count` equalling the cap all come from the external sources listed above — the ssdnodes guide is the main secondary source — and behaviour may differ between versions. This article describes the comparison design, and does not fix one version's exact output format. Second, the context-shift default and its version number (reported as v0.40.11) were not independently verified; older versions, before context shift, may have stopped when the window filled, so this article qualifies the point with "current version" and readers should take their own version's behaviour as authoritative. Third, the OpenAI-compatible endpoint (`/v1/chat/completions`) uses `max_tokens`, not `num_predict`; this article covers only the native `/api/generate` and `/api/chat` endpoints, and mentions the compatible endpoint only as a boundary, without expanding it. Two source conflicts were handled by stating the scope rather than picking a side: the official parameter table gives a default of 128 for `num_predict`, while ssdnodes notes that three setting locations can override each other — the two are not contradictory, because 128 is the default only when nothing is set anywhere, and the request's value wins, so test T1 always begins by reading the model's own parameters with `ollama show --parameters`; and the official API documentation demonstrates only `done_reason` `"stop"`, while ssdnodes reports `"length"` for a capped run — the two are not contradictory, only different in coverage, so this article presents `"length"` as reported by a secondary source and relies on `eval_count` equalling the cap as the numeric proof, which does not depend on which string a version returns.
Frequently asked questions
Why does my answer always stop at about the same length?
Because an output-token cap is firing. A fixed length every time is the signature of `num_predict`: generation stops when the token count reaches the cap, wherever the sentence happens to be. Run test T1 — the same prompt with `num_predict` 128 against -1 — and read `eval_count`. If the count is exactly equal to the cap, the cap is proven by arithmetic.
Why does my answer always stop at the same phrase?
Because the model output a stop sequence. A fixed phrase every time is the signature of the stop list: generation ends the moment the model outputs one of the listed strings, and the string can come from the model's Modelfile, the request's `options.stop`, or a chat tool's default strings. Run test T2 — the same prompt with the stop list present against absent — and watch whether the answer passes the old truncation point.
Why do short questions work, but long questions stop halfway?
Because a cap or a timeout only bites a long answer. A short answer never reaches a 128-token cap and never reaches a 30-second timeout, so it finishes normally. A long answer reaches one of them. That pattern points at the cap or the timeout — not at the model being too weak. Run test T1 for the cap and test T3 for the timeout.
Does raising num_ctx make the answer longer?
No. `num_ctx` is how much the model can read, and `num_predict` is how much it will write. Raising the context window lets the model read a longer prompt and more history; it never lets the answer grow longer. To make an answer longer, raise `num_predict` — in the Modelfile, or in each request's `options`.
My app stops after about 30 seconds every time, but curl finishes. What is wrong?
The app's timeout is the cause. Curl with `--max-time 300` waits five minutes, while the app gives up after about 30 seconds and cuts the connection, even though the server is still generating. That is test T3's positive result: lengthen the app's timeout setting, or change to a client without such a short timeout.
Could keep_alive be unloading the model while it answers?
No. A model answering a request is never unloaded in the middle of generation; the `keep_alive` timer only runs while the model is idle, and it controls how long the model stays loaded after a request finishes. Article #555 states this directly. If an answer stops halfway, the cause is a stop rule — the cap, a stop sequence, or the client timeout — not the lifecycle timer.
I have run all three tests and still cannot separate the cause. What now?
Record six things — `done_reason`, `eval_count`, `num_predict`, the stop list, the client, and the timeout setting — and bring those notes to a check. Do not reinstall Ollama or the model one after another — reinstalling cannot change a generation parameter. If there is a hardware suspicion (for example, the machine itself is unstable, or the graphics card behaves abnormally during generation), the machine can be taken to the workshop for a further check.
Conclusion
An Ollama answer that stops halfway through is a generation-parameter problem with a fixed shape: a connection that works, a model that runs, and an answer cut short by a rule that was set before generation began. The three comparisons in this article — the output cap raised, the stop list removed, and the same request through a patient client — separate the cap, the stop sequence, and the timeout with the response's own fields as the only judge, and each one changes exactly one variable on the same prompt. The excluded comparisons are kept honest too: a full context window does not truncate in the current version, and the lifecycle timer never unloads a model mid-answer.
When to seek professional help: if the model cannot load at all, if inference ends with an out-of-memory error, or if all three tests fail to separate the cause — or if the machine crashes, or the graphics card behaves abnormally during generation — the problem is no longer a generation parameter. It may involve the driver, the installation, or the hardware itself, and is worth having checked by a technician.
If the tests point to a hardware fault rather than a setting — the card is not detected, the machine crashes, or generation fails with an error that no setting changes — the card and the setup can be checked at the Shek Mun workshop: Dali Plaza, Room 1209, Shek Mun, Hong Kong. Phone 2186 8010, WhatsApp 6558 6806. Diagnosis and repair pricing follows the workshop's published three-tier range of HK$400–HK$2,800, quoted before any work begins.