-
-
Notifications
You must be signed in to change notification settings - Fork 9k
style: apply black formatting to fix lint CI (LIT-3274) #28639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
krrish-berri-2
merged 3 commits into
BerriAI:litellm_shin_staging_05_22_2026
from
oss-agent-shin:fix/lit-3274-lint
May 22, 2026
+117
−0
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2112,3 +2112,102 @@ def test_is_already_running_as_role_ssl_verify_passed(): | |
| mock_boto3_client.assert_called_once_with( | ||
| "sts", verify="/path/to/ca-bundle.crt" | ||
| ) | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # LIT-3274: get_bedrock_model_id must strip "bedrock/" prefix and URL-encode | ||
| # ARNs for the invoke path (invoke-with-response-stream). Without this fix | ||
| # 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. | ||
|
Comment on lines
+2120
to
+2122
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| class TestGetBedrockModelIdArnHandling: | ||
| """Unit tests for get_bedrock_model_id with inference-profile ARNs.""" | ||
|
|
||
| ARN = "arn:aws:bedrock:us-east-1:086734376398:inference-profile/global.anthropic.claude-sonnet-4-5-20250929-v1:0" | ||
|
|
||
| def _call(self, model: str, optional_params: dict | None = None) -> str: | ||
| from litellm.llms.bedrock.base_aws_llm import BaseAWSLLM | ||
|
|
||
| provider = BaseAWSLLM.get_bedrock_invoke_provider(model) | ||
| return BaseAWSLLM.get_bedrock_model_id( | ||
| model=model, | ||
| provider=provider, | ||
| optional_params=optional_params or {}, | ||
| ) | ||
|
|
||
| def test_arn_with_bedrock_prefix_is_stripped_and_encoded(self): | ||
| """bedrock/arn:... must not appear verbatim in the model_id.""" | ||
| model_id = self._call(f"bedrock/{self.ARN}") | ||
| assert ( | ||
| "bedrock/arn" not in model_id | ||
| ), f"'bedrock/' prefix not stripped; got: {model_id}" | ||
| # Must be URL-encoded (colons → %3A) | ||
| assert "%3A" in model_id, f"ARN not URL-encoded; got: {model_id}" | ||
| assert "%2F" in model_id, f"ARN slashes not URL-encoded; got: {model_id}" | ||
|
|
||
| def test_arn_with_compound_bedrock_invoke_prefix_is_fully_stripped_and_encoded( | ||
| self, | ||
| ): | ||
| """bedrock/invoke/arn:... — compound prefix — must be fully stripped. | ||
|
|
||
| The old fix used ``break`` after the first matched prefix, so | ||
| ``bedrock/invoke/arn:...`` would only strip ``bedrock/``, leaving | ||
| ``invoke/arn:...``. The subsequent ``.replace('invoke/', '')`` call | ||
| then returned the bare unencoded ARN, reproducing the same | ||
| malformed-URL bug the fix aimed to prevent. | ||
|
|
||
| strip_bedrock_routing_prefix() has no break and handles this correctly. | ||
| """ | ||
| model_id = self._call(f"bedrock/invoke/{self.ARN}") | ||
| assert ( | ||
| "invoke/" not in model_id | ||
| ), f"'invoke/' prefix not stripped; got: {model_id}" | ||
| assert ( | ||
| "bedrock/" not in model_id | ||
| ), f"'bedrock/' prefix not stripped; got: {model_id}" | ||
| assert "%3A" in model_id, f"ARN not URL-encoded; got: {model_id}" | ||
| assert "%2F" in model_id, f"ARN slashes not URL-encoded; got: {model_id}" | ||
|
|
||
| def test_bare_arn_is_encoded(self): | ||
| """Direct ARN without routing prefix must also be URL-encoded.""" | ||
| model_id = self._call(self.ARN) | ||
| assert "%3A" in model_id, f"ARN not URL-encoded; got: {model_id}" | ||
| assert "%2F" in model_id, f"ARN slashes not URL-encoded; got: {model_id}" | ||
|
|
||
| def test_arn_url_matches_expected(self): | ||
| """Full URL built from messages config must match expected encoded form.""" | ||
| import urllib.parse | ||
| from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude3_transformation import ( | ||
| AmazonAnthropicClaudeMessagesConfig, | ||
| ) | ||
|
|
||
| config = AmazonAnthropicClaudeMessagesConfig() | ||
| url = config.get_complete_url( | ||
| api_base=None, | ||
| api_key=None, | ||
| model=f"bedrock/{self.ARN}", | ||
| optional_params={"aws_region_name": "us-east-1"}, | ||
| litellm_params={}, | ||
| stream=True, | ||
| ) | ||
| encoded_arn = urllib.parse.quote(self.ARN, safe="") | ||
| expected = ( | ||
| f"https://bedrock-runtime.us-east-1.amazonaws.com" | ||
| f"/model/{encoded_arn}/invoke-with-response-stream" | ||
| ) | ||
| assert ( | ||
| url == expected | ||
| ), f"URL mismatch:\n got: {url}\n expected: {expected}" | ||
|
|
||
| def test_regular_model_id_unaffected(self): | ||
| """Non-ARN model IDs must continue to work as before.""" | ||
| model_id = self._call("anthropic.claude-3-sonnet-20240229-v1:0") | ||
| assert model_id == "anthropic.claude-3-sonnet-20240229-v1:0" | ||
|
|
||
| def test_invoke_prefixed_model_unaffected(self): | ||
| """invoke/ prefix stripping still works after the fix.""" | ||
| model_id = self._call("invoke/anthropic.claude-3-sonnet-20240229-v1:0") | ||
| assert model_id == "anthropic.claude-3-sonnet-20240229-v1:0" | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strip_bedrock_routing_prefixis 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.