style: apply black formatting to fix lint CI (LIT-3274)#28639
Conversation
…k_model_id for invoke path
The invoke path (used by /v1/messages → Anthropic SDK / Claude Code) called
get_bedrock_model_id() which, when falling back to the raw model string, did
not strip the 'bedrock/' routing prefix and did not URL-encode ARNs.
For a model like:
bedrock/arn:aws:bedrock:us-east-1:<ACCOUNT>:inference-profile/global.anthropic...
the URL built was:
/model/bedrock/arn:aws:bedrock:…/invoke-with-response-stream ❌
Bedrock returned a JSON error body. LiteLLM's AWSEventStreamDecoder passed
those bytes into botocore's EventStreamBuffer which expects binary event-stream
framing. Checksum validation failed on the JSON prelude (0x223a7b22 == ':{"')
producing a misleading botocore.eventstream.ChecksumMismatch instead of the
actual Bedrock error.
Fix: strip 'bedrock/' (and 'invoke/') routing prefix from model string, then
URL-encode if the result is an ARN — matching what the converse path already
does in converse_handler.py.
Fixes: LIT-3274
…fixes
Address greptile review: the original fix used a loop with break, so
bedrock/invoke/arn:... only stripped bedrock/ leaving invoke/arn:...
which is not an ARN → fell through to .replace('invoke/','',1) →
bare unencoded ARN → same malformed-URL bug.
strip_bedrock_routing_prefix() iterates without break, correctly
stripping bedrock/ then invoke/ in sequence. Also adds test case
for the compound-prefix scenario.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Greptile SummaryThis PR is described as a pure formatting fix (Black style) on top of the parent feature branch
Confidence Score: 4/5The logic change is narrow and well-covered by the new unit tests; the main risk is the inline import and a test ARN that uses a real-looking AWS account ID. The routing-prefix stripping and ARN encoding logic is straightforward, the new tests exercise the key scenarios including compound prefixes, and The inline import on line 464 of
|
| Filename | Overview |
|---|---|
| litellm/llms/bedrock/base_aws_llm.py | Adds routing-prefix stripping and ARN URL-encoding to the invoke path inside get_bedrock_model_id; includes an inline function-body import and an early return for ARN models |
| tests/test_litellm/llms/bedrock/test_base_aws_llm.py | Adds TestGetBedrockModelIdArnHandling covering bare ARNs, compound prefixes, and URL construction; tests appear to be pure unit tests without real network calls |
Reviews (1): Last reviewed commit: "style: apply black formatting to fix lin..." | Re-trigger Greptile
0544881
into
BerriAI:litellm_shin_staging_05_22_2026
| from litellm.llms.bedrock.common_utils import strip_bedrock_routing_prefix | ||
|
|
||
| model_id = strip_bedrock_routing_prefix(model_id) |
There was a problem hiding this comment.
The import of
strip_bedrock_routing_prefix is placed inside the function body instead of at the module level. Deferred imports are typically used to break circular dependencies, but there's no comment explaining why that's necessary here. If this location truly is required to avoid a circular import, a short inline comment would clarify intent. Otherwise, moving it to the top of the file keeps the import section clear and avoids the per-call overhead of looking up an already-cached module entry.
| from litellm.llms.bedrock.common_utils import strip_bedrock_routing_prefix | |
| model_id = strip_bedrock_routing_prefix(model_id) | |
| # Deferred to avoid circular import with common_utils. | |
| from litellm.llms.bedrock.common_utils import strip_bedrock_routing_prefix | |
| model_id = strip_bedrock_routing_prefix(model_id) |
| # the Bedrock API receives a malformed URL, returns a JSON error body, and | ||
| # botocore's EventStreamBuffer raises ChecksumMismatch instead of the real | ||
| # error. 0x223a7b22 == ':{\"' — the start of a JSON object. |
There was a problem hiding this comment.
) * fix(bedrock): strip bedrock/ prefix and URL-encode ARNs in get_bedrock_model_id for invoke path The invoke path (used by /v1/messages → Anthropic SDK / Claude Code) called get_bedrock_model_id() which, when falling back to the raw model string, did not strip the 'bedrock/' routing prefix and did not URL-encode ARNs. For a model like: bedrock/arn:aws:bedrock:us-east-1:<ACCOUNT>:inference-profile/global.anthropic... the URL built was: /model/bedrock/arn:aws:bedrock:…/invoke-with-response-stream ❌ Bedrock returned a JSON error body. LiteLLM's AWSEventStreamDecoder passed those bytes into botocore's EventStreamBuffer which expects binary event-stream framing. Checksum validation failed on the JSON prelude (0x223a7b22 == ':{"') producing a misleading botocore.eventstream.ChecksumMismatch instead of the actual Bedrock error. Fix: strip 'bedrock/' (and 'invoke/') routing prefix from model string, then URL-encode if the result is an ARN — matching what the converse path already does in converse_handler.py. Fixes: LIT-3274 * fix(bedrock): use strip_bedrock_routing_prefix to handle compound prefixes Address greptile review: the original fix used a loop with break, so bedrock/invoke/arn:... only stripped bedrock/ leaving invoke/arn:... which is not an ARN → fell through to .replace('invoke/','',1) → bare unencoded ARN → same malformed-URL bug. strip_bedrock_routing_prefix() iterates without break, correctly stripping bedrock/ then invoke/ in sequence. Also adds test case for the compound-prefix scenario. * style: apply black formatting to fix lint CI (LIT-3274) --------- Co-authored-by: oss-agent-shin <ext-agent-shin@berri.ai> Co-authored-by: LiteLLM Bot <bot@berri.ai>
Summary
Fixes the
lintCI failure on #28551 by applyingblackformatting to the two files changed in that PR.What changed
litellm/llms/bedrock/base_aws_llm.pyassertstatements intests/test_litellm/llms/bedrock/test_base_aws_llm.pyto Black styleRelated
Branched from
krrishdholakia1/lit-3274-v1messages-with-bedrock-inference-profile-arns-returns— this PR contains only formatting fixes, zero logic changes.Closes #28551 (or can be merged into it)
Fixes: LIT-3274