Skip to documentation
Documentation navigation

Documentation navigation

Documentation / guides

Finish reasons

Interpret the provider-neutral reason an assistant stopped producing output.

developer

stream.FinishReason normalizes provider stop metadata without pretending every provider has the same vocabulary.

API surface

type FinishReason string

const (
	FinishReasonUnknown       FinishReason = ""
	FinishReasonStop          FinishReason = "stop"
	FinishReasonLength        FinishReason = "length"
	FinishReasonToolUse       FinishReason = "tool_use"
	FinishReasonContentFilter FinishReason = "content_filter"
)
ReasonCaller meaning
FinishReasonUnknownProvider omitted or did not map a reason
FinishReasonStopNormal stop; structured text can be extracted
FinishReasonLengthOutput was cut by a limit; structured extraction fails closed
FinishReasonToolUseAssistant representation is a tool call and may require continuation
FinishReasonContentFilterProvider stopped for filtering; structured extraction fails closed
switch response.FinishReason {
case stream.FinishReasonStop:
	// Safe to inspect normal assistant output.
case stream.FinishReasonToolUse:
	// Continue the tool loop when the representation is a tool call.
default:
	// Handle unknown, length, and filtered output explicitly.
}

Structured output additionally rejects non-empty future reasons with StructuredOutputFinishReasonOther rather than retaining unbounded provider input.

Proof

Related: Structured output, Terminal stream results.

← back to documentation