From c12b3087f5c99b9045012dc7e5c7a7ca907c7bbd Mon Sep 17 00:00:00 2001 From: Ayush Arora Date: Sat, 12 Sep 2026 00:54:47 +0530 Subject: [PATCH] test(bedrock): use monkeypatch for modify_params and remove redundant docstring --- .../chat/test_converse_transformation.py | 73 ++++++++----------- 1 file changed, 30 insertions(+), 43 deletions(-) diff --git a/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py b/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py index c05e74beddf..1751b5680fc 100644 --- a/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py +++ b/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py @@ -6955,51 +6955,38 @@ def test_transform_response_honors_json_mode_kwarg_when_optional_params_lack_it( assert json.loads(result.choices[0].message.content) == {"city": "Paris", "population": 2100000} -def test_transform_request_injects_dummy_tool_without_tools_param(): - """ - Bedrock Converse rejects requests with tool turns when toolConfig is omitted. - LiteLLM must inject a dummy tool without requiring litellm.modify_params. - """ +def test_transform_request_injects_dummy_tool_without_tools_param(monkeypatch): from litellm.llms.bedrock.chat.converse_transformation import AmazonConverseConfig + monkeypatch.setattr(litellm, "modify_params", False) config = AmazonConverseConfig() - prev_modify_params = litellm.modify_params - litellm.modify_params = False - try: - messages = [ - {"role": "user", "content": "Hello"}, - { - "role": "assistant", - "content": "Calling tool", - "tool_calls": [ - { - "id": "tooluse_test_dummy", - "type": "function", - "function": {"name": "get_x", "arguments": "{}"}, - } - ], - }, - { - "role": "tool", - "tool_call_id": "tooluse_test_dummy", - "content": "{}", - }, - ] - result = config.transform_request( - model="anthropic.claude-3-5-sonnet-20240620-v1:0", - messages=messages, - optional_params={}, - litellm_params={}, - headers={}, - ) - finally: - litellm.modify_params = prev_modify_params - assert "toolConfig" in result - tools = result["toolConfig"].get("tools", []) - tool_names = [ - t.get("toolSpec", {}).get("name") - for t in tools - if isinstance(t, dict) and "toolSpec" in t + messages = [ + {"role": "user", "content": "Hello"}, + { + "role": "assistant", + "content": "Calling tool", + "tool_calls": [ + { + "id": "tooluse_test_dummy", + "type": "function", + "function": {"name": "get_x", "arguments": "{}"}, + } + ], + }, + { + "role": "tool", + "tool_call_id": "tooluse_test_dummy", + "content": "{}", + }, ] - assert "dummy_tool" in tool_names + result = config.transform_request( + model="anthropic.claude-3-5-sonnet-20240620-v1:0", + messages=messages, + optional_params={}, + litellm_params={}, + headers={}, + ) + assert "toolConfig" in result + assert "tools" in result["toolConfig"] + assert result["toolConfig"]["tools"][0]["toolSpec"]["name"] == "dummy_tool"