From b455ada161eca9557be66f2e06f011a04baa62ee Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Tue, 5 Aug 2025 17:46:40 -0700 Subject: [PATCH] [Bug Fix] [Bug]: New Databricks Foundation Models databricks-gpt-oss-20b and databricks-gpt-oss-120b failed with error: litellm.APIConnectionError: 'signature' (#13318) * test_transform_choices_without_signature * fix ChatCompletionThinkingBlock * extract_reasoning_content --- .../llms/databricks/chat/transformation.py | 4 +- litellm/proxy/proxy_config.yaml | 4 +- .../test_databricks_chat_transformation.py | 45 +++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/litellm/llms/databricks/chat/transformation.py b/litellm/llms/databricks/chat/transformation.py index e7d7920769f..908419f7193 100644 --- a/litellm/llms/databricks/chat/transformation.py +++ b/litellm/llms/databricks/chat/transformation.py @@ -371,8 +371,8 @@ class DatabricksConfig(DatabricksBase, OpenAILikeChatConfig, AnthropicConfig): reasoning_content += sum["text"] thinking_block = ChatCompletionThinkingBlock( type="thinking", - thinking=sum["text"], - signature=sum["signature"], + thinking=sum.get("text", ""), + signature=sum.get("signature", ""), ) if thinking_blocks is None: thinking_blocks = [] diff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yaml index 7aababa79d4..c8d148f7086 100644 --- a/litellm/proxy/proxy_config.yaml +++ b/litellm/proxy/proxy_config.yaml @@ -1,6 +1,6 @@ model_list: - - model_name: vertex_ai/* + - model_name: anthropic/* litellm_params: - model: vertex_ai/* + model: anthropic/* diff --git a/tests/test_litellm/llms/databricks/chat/test_databricks_chat_transformation.py b/tests/test_litellm/llms/databricks/chat/test_databricks_chat_transformation.py index 1026a210098..fc44d44aba9 100644 --- a/tests/test_litellm/llms/databricks/chat/test_databricks_chat_transformation.py +++ b/tests/test_litellm/llms/databricks/chat/test_databricks_chat_transformation.py @@ -45,3 +45,48 @@ def test_transform_choices(): assert choices[0].message.reasoning_content == "i'm thinking." assert choices[0].message.thinking_blocks is not None assert choices[0].message.tool_calls is None + + +def test_transform_choices_without_signature(): + """ + Test that the transformation works correctly when the signature field is missing + from the summary, which occurs with new Databricks Foundation Models like + databricks-gpt-oss-20b and databricks-gpt-oss-120b. + """ + config = DatabricksConfig() + databricks_choices = [ + { + "message": { + "role": "assistant", + "content": [ + { + "type": "reasoning", + "summary": [ + { + "type": "summary_text", + "text": "i'm thinking without signature.", + # Note: no signature field here + } + ], + }, + {"type": "text", "text": "Response without signature"}, + ], + }, + "index": 0, + "finish_reason": "stop", + } + ] + + # This should not raise a KeyError for missing signature + choices = config._transform_dbrx_choices(choices=databricks_choices) + + assert len(choices) == 1 + assert choices[0].message.content == "Response without signature" + assert choices[0].message.reasoning_content == "i'm thinking without signature." + assert choices[0].message.thinking_blocks is not None + assert len(choices[0].message.thinking_blocks) == 1 + + # Verify the thinking block was created successfully without signature + thinking_block = choices[0].message.thinking_blocks[0] + assert thinking_block["type"] == "thinking" + assert thinking_block["thinking"] == "i'm thinking without signature."