Skip to content

fix: raise ValueError when model is None in Bedrock client#1232

Open
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
MaxwellCalkin:fix/bedrock-model-none-check
Open

fix: raise ValueError when model is None in Bedrock client#1232
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
MaxwellCalkin:fix/bedrock-model-none-check

Conversation

@MaxwellCalkin
Copy link

Summary

When using the Bedrock client, if model is not provided in the request body, options.json_data.pop("model", None) returns None. This None is then passed to str(), 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:

# model not provided → silent conversion to string "None"
# API call to /model/None/invoke → confusing Bedrock error

After this fix:

# model not provided → immediate ValueError: "model is required for Bedrock API calls"

Changes

  • Added an explicit None check after popping the model from json_data in _prepare_options() in src/anthropic/lib/bedrock/_client.py
  • Raises ValueError with a clear message when model is missing

Context

The Vertex client (src/anthropic/lib/vertex/_client.py) already handles this correctly by using .pop("model") without a default value, which raises a KeyError if model is missing. This fix brings the Bedrock client in line with that behavior by providing a clear, descriptive error.

Test plan

  • Verified the fix raises ValueError when model is None
  • Verified normal operation is unaffected when model is provided
  • Confirmed the Vertex client already handles this case (no default value on .pop())

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.
@MaxwellCalkin MaxwellCalkin requested a review from a team as a code owner March 8, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant