A model ends its reply by choosing a stop token like any other word
The model learns that stop token in post-training, and a separate length cap can cut a reply off mid-word before it ever arrives.
Why this matters
Every chatbot reply ends, and you have watched them end in two very different ways. Some come to rest on a finished thought. Some stop dead in the middle of a word, as if a plug were pulled. Those are not the same event, and telling them apart tells you what to do next: try again, or ask for more. This lesson follows a reply's ending back to its cause. A model stops by picking a special end-of-turn token out of its vocabulary, the same way it picks every other word. That choice was trained into it after the model was built, not worked out from grammar. And a length limit in the program running the model can cut a reply off before that token ever arrives. By the end you can look at any stopped reply and say which of the two stopped it.
- 01
- The instant a model writes a token, it becomes fact: how a model builds a reply one token at a time.
- 02
- Two answers to one prompt diverge at a single draw: how one token gets drawn from the model's probabilities.
Two ways a reply can end
A reply that comes back through a serving system carries a note about
why it stopped. The Anthropic Messages API returns a
stop_reason field, and its value is
end_turn when the model reached a natural stopping point
and max_tokens when a requested length limit was
hit.1 Two codes, two
different causes. One is a decision the model made. The other is a
limit imposed on it from outside. The clean sentence you see and the
word snapped in half you sometimes see are those two causes leaving
their marks.
The stop is one more token the model samples
A model writes a reply one token at a time, a token being a chunk of text, usually a word or a piece of one. At each position it produces a probability for every token in its vocabulary, and one token is drawn from those probabilities and added to the reply.
The vocabulary includes a token that means the turn is over. Llama 3
writes it <|eot_id|>, an end-of-turn marker Meta's
model documentation says the model emits once it "has determined that
it has finished interacting with the user
message."2 It is an
ordinary entry in the vocabulary. Meta and PyTorch's tokenizer gives
it the integer id 128009, sitting in the same table as
every word-piece.3 At
each step the model puts some probability on 128009
exactly as it puts probability on "Paris" or "the." When the sampler
draws that token, the decoding loop returns: the library that runs an
open model stops as soon as the end-of-sequence token is
produced.4 Emitting that
token is the signal that ends
generation.5 Stopping is
not a separate part bolted onto generation. It is next-token
prediction landing on the stop token.
Watch the probability of that token as an answer completes. Give the model "What is the capital of France?" and start it writing "The capital of France is." After "is," you would put nearly all your weight on "Paris" and almost none on the turn ending right there, because an answer word still has to come. After "Paris." the weight flips: nothing sensible remains to add, and the end-of-turn token becomes the likely next pick.
| After the model has written | P(end-of-turn) | What is happening |
|---|---|---|
| The | ~0.0% | the answer has not started |
| France is | ~0.1% | an answer word still has to follow |
| Paris | ~3% | a closing period could still come |
| Paris. | ~92% | nothing sensible remains to add |
The trajectory is checkable, even if these numbers are illustration. Hugging Face's generation tools can print the probability the model assigned to any token at any step, so anyone can run this and read the real curve of the end-of-turn token's probability.4 Two levers in the same toolkit show the token is ordinary and not a hard rule. You can drive its probability to nothing so the model cannot stop yet, and you can force it at a length limit. A rule could not be switched off. A token can.4
Post-training taught the model where a turn ends
Where did the model learn to put high probability on the end-of-turn
token at the close of a good answer? Not from grammar it worked out on
its own. A model begins as a base model, trained to continue text by
predicting the next token across a large pile of documents. A base
model is not unable to stop. It emits an end-of-document token at a
document boundary. Llama's base model produces
<|end_of_text|>, which Meta says "is generated only
by the base models,"2 and
Qwen's base model uses <|endoftext|>, a marker
inserted between documents in its training
data.6 What a base model
lacks is the habit of ending at the close of a helpful answer, because
in a stream of documents there is no turn to end.
Post-training put that habit in. A base model is fine-tuned for chat
on data formatted as a sequence of messages, each turn wrapped in
control tokens, and it learns to produce the end-of-turn token where a
turn should close.7 Qwen
sets its end-of-turn token <|im_end|> as the model's
end-of-sequence token for chat, so producing it halts generation at a
turn boundary.6 This is
settled engineering, done on purpose, and the same across vendors.
The wider finding behind it is that size alone does not buy this. The InstructGPT work at OpenAI showed that making a base model bigger does not by itself make it follow a user's intent. Fine-tuning with human feedback is what aligns a model to that intent, and a much smaller fine-tuned model is preferred over the far larger base.8 Stopping at the end of a helpful answer is one of those trained-in behaviors.
A base model does stop. It ends a document with a document-end token. Post-training does not teach a model to stop at all; it teaches the model where a turn ends, so it closes at the end of an answer instead of running on into the next imagined document.2
The program that runs the model can stop it too
Everything so far is the model's own doing. The second cause is not.
The model does not run itself. A serving program feeds it tokens and
collects what it produces, and that program holds a limit on how many
tokens it will accept back. In the Anthropic Messages API that limit
is max_tokens, "the maximum number of tokens to generate
before stopping."1 When
the count is reached, the program stops collecting and returns
whatever it has, whether or not the end-of-turn token ever came. The
reply is truncated. Anthropic reports this ending as
max_tokens rather than
end_turn.1
Google's Gemini API reports the same event as a
finishReason of MAX_TOKENS rather than
STOP.9 The
model did not stop itself. The program stopped it.
A caller can also hand the program a stop sequence, a string that forces a halt the moment the model produces it.1 And these are not the whole list: the same Anthropic field can also report that the model refused, that it paused to use a tool, or that the context window filled.1 Those endings are real but uncommon. The two you meet every day are the model's own end-of-turn token and the program's length cap.
The two endings leave different marks on the screen
You can usually tell which of the two ended a reply without reading any API field, because they leave different marks. The model's own ending lands on a boundary: a finished sentence, a closed code block, a completed list. It chose the end-of-turn token because nothing sensible remained to add, so the last thing on the screen is whole. A length cap has no such sense. It stops at a token count, wherever that count happens to fall, in the middle of "argu" with "ment" never written, or after the opening brace of a function whose body never comes.
A reply that reads "returns the sum of the two
argu" was cut off by the cap, and reports
max_tokens; the fix is to raise the limit and run it
again, not to re-ask the model. A reply that reads "returns the sum of
the two arguments." finished on its own and reports
end_turn.1
The first is the program's wall. The second is the model deciding it
was done.
The takeaway
A reply ends for one of two reasons, and they belong to two different actors. The model ends its own turn by sampling the end-of-turn token, a real entry in its vocabulary that post-training taught it to produce at the close of a good answer. The program running the model ends the turn from outside, by refusing to collect more than its token limit. The first leaves a whole thought on the screen and reports end_turn. The second can leave a word cut in half and reports max_tokens. A reply that stops on a finished thought is the model's own doing. A reply that stops mid-word is the program's, and no amount of re-asking the model will change that. Now you know which one you are looking at.
- 01
- Hugging Face, Chat templates: how a base model is formatted and fine-tuned into a chat model, control tokens and all.
- 02
- Ouyang et al., Training language models to follow instructions: the study behind the claim that helpful behavior is added by fine-tuning, not by size.
Sources
- Anthropic · Messages API reference
- Meta · Llama 3.1 prompt format and special tokens
- Meta / PyTorch · torchtune Llama 3 tokenizer source
- Hugging Face · Transformers text generation reference
- Nate Brake · The end-of-sequence token, explained
- Qwen · Key concepts (control tokens)
- Hugging Face · Chat templates
- Ouyang et al. · Training language models to follow instructions with human feedback
- Google · Gemini API generateContent reference