Repository navigation
fix(bedrock): forward stop and max_completion_tokens as sent on Claude InvokeModel - #1344
Merged
Merged
Conversation
…e InvokeModel Non-streamed chat to Claude on Bedrock goes through InvokeModel, which builds its body with the shared Anthropic request builder and then re-derived `stop_sequences` from `stop` with the Converse helper. That helper drops empty strings and ignores anything that is not a string or an array, and the shaping step then removed `stop` and `max_completion_tokens` unconditionally. So `stop: 5`, `stop: ""`, `stop: ["", "x"]` and a non-integer `max_completion_tokens` were silently dropped or filtered on this route, while the Anthropic route forwards them and lets the upstream reject them. The re-derivation and both removals are gone: the body keeps what the shared builder produced, so InvokeModel now matches the Anthropic route for every input. A native `stop_sequences` still wins over `stop`, a string `stop` is still a one-element array, and `null` or `[]` still sets nothing.
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.
Non-streamed chat to Claude on Amazon Bedrock now forwards
stopandmax_completion_tokensthe same way the Anthropic route does, instead of silently dropping or filtering values it can't map.The InvokeModel path builds its body with the shared Anthropic request builder, but
shape_invoke_bodythen re-derivedstop_sequencesfromstopusing the Converse helper (which drops empty strings and ignores non-string values) and removedstopandmax_completion_tokensunconditionally. The result was thatstop: 5and a non-integermax_completion_tokensvanished from the request andstop: ""/["", "gamma"]lost their empty entries, so these requests got a 200 that ignored what the caller asked for. On the Anthropic route the same requests reach the upstream as sent and are rejected with a 400.The fix removes that re-derivation and the two removals, so the InvokeModel body carries exactly what the shared builder produced. Unchanged: a native
stop_sequencesstill wins overstop, a stringstopbecomes a one-element array, andnullor[]sets nothing. A side effect is that a provider-key body override ofstop_sequencesis no longer overwritten on this route.Behavior change after upgrading: a non-streamed chat request to a Bedrock Claude model carrying an invalid
stop(a number, an empty string, an array with an empty string) or a non-integermax_completion_tokensnow gets the upstream's 400 (e.g.stop_sequences: each stop sequence must be non-empty,stop: Extra inputs are not permitted) instead of a 200 that ignored the value. Valid values behave as before. Streamed Bedrock chat and non-Claude Bedrock models use Converse, which builds a typed request, and are not changed here.Tests: the InvokeModel mock test
chat_anthropic_maps_max_completion_tokens_and_stopnow pins forwarding of empty stop strings,null/[], an unmappablestopand a non-integermax_completion_tokens, and a new case inbedrock-converse-and-chat-completions-e2echecks the body a non-streamed Claude request puts on/invokefor the same inputs. Both fail against the previousmain.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests