[Platform] Normalize finish_reason metadata across all bridges#2290
Open
chr-hertel wants to merge 2 commits into
Open
[Platform] Normalize finish_reason metadata across all bridges#2290chr-hertel wants to merge 2 commits into
chr-hertel wants to merge 2 commits into
Conversation
OskarStark
approved these changes
Jul 9, 2026
1f17009 to
b22c4b5
Compare
b22c4b5 to
b97a6a4
Compare
…acing LENGTH Some providers (Anthropic among them) throw MaxOutputTokensException mid-stream on an output token limit truncation rather than emitting a LENGTH finish reason, so the same max_tokens case differs between buffered and streamed results.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #2276, which exposed the raw streamed
finish_reasonfor the OpenAI-compatible bridges only.FinishReason\FinishReason+FinishReason\FinishReasonCase, normalizing the divergent provider vocabularies (length/max_tokens/MAX_TOKENS/max_output_tokens) intoSTOP,LENGTH,TOOL_CALL,CONTENT_FILTER,STOP_SEQUENCE,OTHERwhilegetRaw()keeps the provider value.finish_reasonresult metadata for buffered and streamed results across OpenAI, Anthropic, Gemini, VertexAI, Bedrock, Azure, Ollama, Cohere, Mistral, DeepSeek, Cerebras, Scaleway, Docker Model Runner, Perplexity, MiniMax, amazee.ai and Generic.MetadataDelta, after the deltas of the chunk that carried it (providers such as Mistral bundle the last content token withfinish_reason).Docs in
docs/components/platform.rst, runnable example inexamples/misc/finish-reason.php.Known gap: the OpenAI Responses API signals a truncated stream with
response.incomplete, which the bridge raises as an exception, so there is no result left to carry the reason. Left as-is; changing it is a behavior change beyond this PR.