fix: raise ValueError when model is None in Bedrock client#1232
Open
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
Open
fix: raise ValueError when model is None in Bedrock client#1232MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
Conversation
When model is not provided in json_data, `options.json_data.pop("model", None)`
returns None. This None value is then passed to `str()`, producing the literal
string "None", which gets URL-encoded and sent as the model ID in the Bedrock
API URL (e.g., `/model/None/invoke`). This results in a confusing API error
from Bedrock rather than a clear client-side error.
Add an explicit check after popping the model to raise a descriptive ValueError
immediately, matching the behavior of the Vertex client which already raises
KeyError when model is missing.
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.
Summary
When using the Bedrock client, if
modelis not provided in the request body,options.json_data.pop("model", None)returnsNone. ThisNoneis then passed tostr(), producing the literal string"None", which gets URL-encoded and used in the Bedrock API URL (e.g.,/model/None/invoke). This causes a confusing error from the Bedrock API rather than a clear client-side error.Before this fix:
After this fix:
Changes
Nonecheck after popping the model fromjson_datain_prepare_options()insrc/anthropic/lib/bedrock/_client.pyValueErrorwith a clear message when model is missingContext
The Vertex client (
src/anthropic/lib/vertex/_client.py) already handles this correctly by using.pop("model")without a default value, which raises aKeyErrorif model is missing. This fix brings the Bedrock client in line with that behavior by providing a clear, descriptive error.Test plan
ValueErrorwhenmodelisNonemodelis provided.pop())