From 6676285789b57817cc4bf55f10bdede465afc079 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Sat, 31 Oct 2026 01:55:54 -0700 Subject: [PATCH] fix(databricks): reject a text part holding a non-string locally with a clear 400 --- .../llms/databricks/chat/transformation.py | 7 +++++-- .../providers/test_databricks_chat_wire.py | 2 +- .../test_databricks_chat_transformation.py | 19 ++++++++++++------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/litellm/llms/databricks/chat/transformation.py b/litellm/llms/databricks/chat/transformation.py index 34312ac55c7..f55c6d936f6 100644 --- a/litellm/llms/databricks/chat/transformation.py +++ b/litellm/llms/databricks/chat/transformation.py @@ -189,8 +189,11 @@ def _is_empty_text_block(block: object) -> bool: match block: case {"type": "text", "text": str() as text}: return not text.strip() - case {"type": "text", "text": object() as text}: - return not text + case {"type": "text", "text": object() as text} if text: + raise DatabricksException( + status_code=400, + message=f"A text content block needs a string 'text', got {type(text).__name__}", + ) case {"type": "text"}: return True case _: diff --git a/tests/integration/providers/test_databricks_chat_wire.py b/tests/integration/providers/test_databricks_chat_wire.py index 7aded66e763..3d9d749eb04 100644 --- a/tests/integration/providers/test_databricks_chat_wire.py +++ b/tests/integration/providers/test_databricks_chat_wire.py @@ -1616,7 +1616,7 @@ def test_databricks_non_string_text_block_is_rejected_before_reaching_upstream(g ) received: Final = wire.drain() assert response.status_code == 400, response.text - assert "'int' object has no attribute 'strip'" in response.text + assert "A text content block needs a string 'text', got int" in response.text assert received == () diff --git a/tests/unit/llms/databricks/chat/test_databricks_chat_transformation.py b/tests/unit/llms/databricks/chat/test_databricks_chat_transformation.py index 0a6296fe1b9..a36ab153a9f 100644 --- a/tests/unit/llms/databricks/chat/test_databricks_chat_transformation.py +++ b/tests/unit/llms/databricks/chat/test_databricks_chat_transformation.py @@ -21,6 +21,7 @@ from litellm.constants import ( DEFAULT_REASONING_EFFORT_MEDIUM_THINKING_BUDGET, ) from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler +from litellm.llms.databricks.common_utils import DatabricksException from litellm.llms.databricks.chat.transformation import ( DatabricksChatResponseIterator, DatabricksConfig, @@ -701,14 +702,18 @@ def test_transform_request_joins_plain_text_blocks_only_for_hosted_non_claude_js assert _outgoing_messages(model, messages, optional_params) == [{"role": "user", "content": expected_content}] -def test_transform_request_keeps_a_text_block_whose_text_is_a_truthy_non_string() -> None: - block: Final = {"type": "text", "text": 7} +@pytest.mark.parametrize("response_format", [None, {"type": "json_object"}], ids=["no-response-format", "json-object"]) +def test_transform_request_rejects_a_text_block_whose_text_is_a_truthy_non_string( + response_format: dict[str, str] | None, +) -> None: + with pytest.raises(DatabricksException) as error: + _outgoing_messages( + "databricks-meta-llama-3-3-70b-instruct", + [{"role": "user", "content": [{"type": "text", "text": "Reply in JSON"}, {"type": "text", "text": 7}]}], + {} if response_format is None else {"response_format": response_format}, + ) - assert _outgoing_messages( - "databricks-meta-llama-3-3-70b-instruct", - [{"role": "user", "content": [block]}], - {}, - ) == [{"role": "user", "content": [block]}] + assert error.value.status_code == 400 def test_transform_request_json_object_keeps_earlier_turns_as_sent() -> None: