Skip to content
47% off: the complete course for $79 (reg. $149)Order now →
AI Builder

AI builder glossary

Stop reason

The field in a model response that says why generation ended, such as finishing normally, hitting the token cap, calling a tool, or refusing.

Every response tells you why the model stopped. On the Claude API the field is stop_reason, with values including end_turn (finished naturally), max_tokens (hit your output cap), stop_sequence (matched one of your stop strings), tool_use (wants your code to run a tool), pause_turn, and refusal. Other providers expose the same idea under names like finish reason.

Checking it is one of the cheapest reliability wins in an AI feature, and one of the most skipped. A max_tokens stop means the output is truncated, so a JSON payload may be incomplete and a summary may end mid-sentence. A tool_use stop means the model is waiting for a tool result, not done. A refusal means the content shouldn't be shown or parsed as a normal answer.

Branch on the stop reason before you use the content. Retry truncated outputs with a higher cap or a shorter task, route refusals to a fallback message, and continue the loop on tool calls. Log the stop reason with every call, too; a rising share of max_tokens stops after a prompt change is an early warning that outputs grew longer than you planned.

Example

An invoice extractor sees occasional parse failures. The logs show every failure has a max_tokens stop reason on long invoices, so the team raises the cap for that route and adds a retry path when truncation happens.

Learn more in the course

Related terms

Go from definitions to doing

Learn to build AI-powered apps in 132 practical lessons.