From 01ddfca9a9a4620b41e803890457d9cb0b63b8d5 Mon Sep 17 00:00:00 2001 From: Kaustubh Anil Jain <78426775+kaust1495@users.noreply.github.com> Date: Thu, 22 Oct 2026 08:49:32 +0530 Subject: [PATCH] test(bedrock): restore litellm.model_cost via monkeypatch in Claude 5 structured-output regression test Fixes the TQ005 test-quality gate failure on the PR: the regression test mutated the litellm.model_cost process-wide global with manual save/restore; monkeypatch.setattr restores it at teardown instead. --- .../chat/test_converse_transformation.py | 69 ++++++++----------- 1 file changed, 30 insertions(+), 39 deletions(-) diff --git a/tests/unit/llms/bedrock/chat/test_converse_transformation.py b/tests/unit/llms/bedrock/chat/test_converse_transformation.py index efe6371122d..1950801b35b 100644 --- a/tests/unit/llms/bedrock/chat/test_converse_transformation.py +++ b/tests/unit/llms/bedrock/chat/test_converse_transformation.py @@ -4867,47 +4867,38 @@ def test_translate_response_format_native_output_config_claude_5_family(monkeypa Regression test for: https://github.com/BerriAI/litellm/issues/47687 """ - old_env = os.environ.get("LITELLM_LOCAL_MODEL_COST_MAP") - old_cost = litellm.model_cost monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True") - litellm.model_cost = litellm.get_model_cost_map(url="") - try: - config = AmazonConverseConfig() - response_format = { - "type": "json_schema", - "json_schema": { - "name": "ScoreResult", - "schema": { - "type": "object", - "properties": {"score": {"type": "number"}}, - "required": ["score"], - }, + monkeypatch.setattr(litellm, "model_cost", litellm.get_model_cost_map(url="")) + config = AmazonConverseConfig() + response_format = { + "type": "json_schema", + "json_schema": { + "name": "ScoreResult", + "schema": { + "type": "object", + "properties": {"score": {"type": "number"}}, + "required": ["score"], }, - } - for model in ( - "us.anthropic.claude-opus-5-5", - "us.anthropic.claude-sonnet-5-5", - "us.anthropic.claude-haiku-5-5", - "anthropic.claude-opus-5", - "anthropic.claude-sonnet-5", - ): - optional_params: dict = {} - result = config._translate_response_format_param( - value=response_format, - model=model, - optional_params=optional_params, - non_default_params={"response_format": response_format}, - is_thinking_enabled=False, - ) - assert "outputConfig" in result, f"{model}: json_schema should route to native outputConfig without thinking" - assert "tools" not in result, f"{model}: json tool path must not be used for Claude 5 family" - assert "tool_choice" not in result - finally: - litellm.model_cost = old_cost - if old_env is None: - os.environ.pop("LITELLM_LOCAL_MODEL_COST_MAP", None) - else: - monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", old_env) + }, + } + for model in ( + "us.anthropic.claude-opus-5-5", + "us.anthropic.claude-sonnet-5-5", + "us.anthropic.claude-haiku-5-5", + "anthropic.claude-opus-5", + "anthropic.claude-sonnet-5", + ): + optional_params: dict = {} + result = config._translate_response_format_param( + value=response_format, + model=model, + optional_params=optional_params, + non_default_params={"response_format": response_format}, + is_thinking_enabled=False, + ) + assert "outputConfig" in result, f"{model}: json_schema should route to native outputConfig without thinking" + assert "tools" not in result, f"{model}: json tool path must not be used for Claude 5 family" + assert "tool_choice" not in result CAPITAL_RESPONSE_FORMAT: Final = {