stop reason
The field in a model reply that says why generation ended, such as a natural end, the token cap, a stop sequence, a tool call or a refusal.
In more detail
Anthropic's values include end_turn, max_tokens, stop_sequence, tool_use, pause_turn and refusal; OpenAI uses finish_reason with values such as stop, length and tool_calls. Check it before trusting or parsing the text, because a truncated or refused reply can look like a normal one.
Example
"stop_reason": "max_tokens"Related terms
- max tokens — The request parameter that caps how many tokens the model may generate in one reply.
- refusal — A reply in which a model declines to do what was asked, for safety reasons or because it lacks the information.
- tool call — A model's structured request to run one tool with given arguments, returned instead of, or alongside, text.
Taught in
- How The Next Token Is Chosen — AI Engineering: LLM Apps, RAG & Agents
- The Request And The Response — AI Engineering: LLM Apps, RAG & Agents
- Streaming Responses — AI Engineering: LLM Apps, RAG & Agents
- Anatomy Of A Prompt — AI Engineering: LLM Apps, RAG & Agents
- Structured Output — AI Engineering: LLM Apps, RAG & Agents
- Function Calling — AI Engineering: LLM Apps, RAG & Agents
- The Agent Loop — AI Engineering: LLM Apps, RAG & Agents
- Tracing And Monitoring — AI Engineering: LLM Apps, RAG & Agents
References
- Anthropic: Messages API reference (temperature, top_k, top_p, stop_sequences, stop_reason)
- Anthropic: Handle tool calls (tool_result and is_error)