Skip to content

fix(databricks): send a single plain text block as a string for non-Claude models - #45686

Merged
mateo-berri merged 12 commits into
mainfrom
litellm_databricks_single_text_block_as_string
Oct 14, 2026
Merged

mateo-berri merged 12 commits into
mainfrom
litellm_databricks_single_text_block_as_string

Conversation

@mrinal-berri

@mrinal-berri mrinal-berri commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Databricks json_object 400s with "must contain the word json"
  • Happens when message content is a one-block text list
  • model_info.mode: responses deployments always send that list shape

How it solves it:

  • Databricks non-Claude models get a single plain text block as a string
  • Blocks with cache_control, images, or several blocks stay lists
  • Claude models on Databricks are unchanged

The fix lives in the Databricks layer, not the bridge, because a direct /v1/chat/completions call with one text block in a list hits the same 400. A bridge-only fix like #45713 leaves that case broken. It runs for every non-Claude request, not only with response_format: json_object, since a lone text block and a string reach the model as the same prompt. The collapse runs before system messages are merged, so a run of one-block system messages now joins with a blank line, the same way two string system messages already join on main. The author kept that join in ec4d6ee, which updates the bridge test to expect it, and it is also the form Llama 4 Maverick reads in full (see Caveats)

User Flow

Before: a developer whose Databricks deployment has model_info.mode: responses gets a 400 in JSON mode even though their prompt says "JSON"

  1. They send POST https://litellm-domain/v1/chat/completions to a Databricks Llama deployment with "content": "Reply in JSON with key a. hi" and "response_format": {"type": "json_object"}
  2. The proxy returns HTTP 400 "messages" must contain the word "json" in some form, to use "response_format" of type "json_object"
  3. Sending the same text as a one-item [{"type": "text", ...}] list to a plain Databricks deployment fails the same way

After: the same requests succeed and return JSON

  1. They send the same POST https://litellm-domain/v1/chat/completions to the same deployment
  2. The proxy returns HTTP 200 with {"a": "hi"} as the message content
  3. The one-item text list request to the plain deployment also returns HTTP 200

Relevant issues

Fixes #45618

Linear ticket

Resolves LIT-9393

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Last updated: 0f4f923, a clean merge of main. QA and /live-pr-risk ran on 170755a, the last commit with a product diff

Live A/B on real Databricks (Azure workspace, real $$$, no mocks): the same curl requests sent to a proxy booted at the merge base and to one booted at the PR tip, each one process with 2 uvicorn workers on its own random port and its own Postgres database, same config. dbx-llama70b-responses is databricks/databricks-meta-llama-3-3-70b-instruct with model_info.mode: responses (the reported setup), dbx-qwen35 is a plain databricks/databricks-qwen35-122b-a10b deployment, dbx-claude is databricks/databricks-claude-sonnet-5-5. gw-llama-responses is databricks/system.ai.meta-llama-3-3-70b-instruct with model_info.mode: responses, which goes out on Databricks' AI Gateway route /ai-gateway/mlflow/v1/chat/completions like the reporter's model. The verdict rests only on what the caller gets back: the HTTP status and body. Long ids and the Qwen reasoning text are elided in the outputs below, nothing else is edited

Before (96ac1ec)

Chat, bridged deployment, string content (the reported case)

curl -sS -w '\nHTTP %{http_code}\n' http://127.0.0.1:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"dbx-llama70b-responses","messages":[{"role":"user","content":"Reply in JSON with key result set to ok."}],"response_format":{"type":"json_object"},"max_tokens":60,"temperature":0}'
{"error":{"message":"litellm.BadRequestError: DatabricksException - {\"error_code\":\"BAD_REQUEST\",\"message\":\"\\\"messages\\\" must contain the word \\\"json\\\" in some form, to use \\\"response_format\\\" of type \\\"json_object\\\".\\n\"}\n\nLiteLLM: model group 'dbx-llama70b-responses' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400

Chat, plain deployment, one text block in a list

curl -sS -w '\nHTTP %{http_code}\n' http://127.0.0.1:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"dbx-qwen35","messages":[{"role":"user","content":[{"type":"text","text":"Reply in JSON with key result set to ok."}]}],"response_format":{"type":"json_object"},"max_tokens":400,"temperature":0}'
{"error":{"message":"litellm.BadRequestError: DatabricksException - {\"error_code\":\"BAD_REQUEST\",\"message\":\"\\\"messages\\\" must contain the word \\\"json\\\" in some form, to use \\\"response_format\\\" of type \\\"json_object\\\".\\n\"}\n\nLiteLLM: model group 'dbx-qwen35' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400

/v1/responses, one input_text block, json_object text format

curl -sS -w '\nHTTP %{http_code}\n' http://127.0.0.1:$PORT/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"dbx-qwen35","input":[{"role":"user","content":[{"type":"input_text","text":"Reply in JSON with key result set to ok."}]}],"text":{"format":{"type":"json_object"}},"max_output_tokens":400,"temperature":0}'
{"error":{"message":"litellm.BadRequestError: DatabricksException - {\"error_code\":\"BAD_REQUEST\",\"message\":\"\\\"messages\\\" must contain the word \\\"json\\\" in some form, to use \\\"response_format\\\" of type \\\"json_object\\\".\\n\"}\n\nLiteLLM: model group 'dbx-qwen35' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400

/v1/messages, one text block, output_format json_schema

curl -sS -w '\nHTTP %{http_code}\n' http://127.0.0.1:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"dbx-qwen35","max_tokens":60,"messages":[{"role":"user","content":[{"type":"text","text":"Reply in JSON with key result set to ok."}]}],"output_format":{"type":"json_schema","schema":{"type":"object","properties":{"result":{"type":"string"}},"required":["result"]}}}'
{"id":"chatcmpl_...elided","type":"message","role":"assistant","model":"dbx-qwen35","stop_sequence":null,"usage":{"input_tokens":157,"output_tokens":60},"content":[{"type":"thinking","thinking":"Thinking Process:\n\n1.  **Analyze the Request:**\n    *   Input: \"Reply in JSO...elided","signature":""},{"type":"text","text":""}],"stop_reason":"max_tokens","stop_details":null}
HTTP 200

Chat, AI Gateway route, bridged system.ai model (the reporter's route)

curl -sS -w '\nHTTP %{http_code}\n' http://127.0.0.1:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"gw-llama-responses","messages":[{"role":"user","content":"Reply in JSON with key result set to ok."}],"response_format":{"type":"json_object"},"max_tokens":30}'
{"error":{"message":"litellm.BadRequestError: DatabricksException - {\"error_code\":\"BAD_REQUEST\",\"message\":\"\\\"messages\\\" must contain the word \\\"json\\\" in some form, to use \\\"response_format\\\" of type \\\"json_object\\\".\\n\"}\n\nLiteLLM: model group 'gw-llama-responses' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: dbx-broken. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.","type":"invalid_req ...rest of the body cut off by the capture script
HTTP 400

After (170755a)

Chat, bridged deployment, string content (the reported case)

curl -sS -w '\nHTTP %{http_code}\n' http://127.0.0.1:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"dbx-llama70b-responses","messages":[{"role":"user","content":"Reply in JSON with key result set to ok."}],"response_format":{"type":"json_object"},"max_tokens":60,"temperature":0}'
{"id":"chatcmpl_...elided","created":1791743155,"model":"dbx-llama70b-responses","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"{\"result\": \"ok\"}","role":"assistant"}}],"usage":{"completion_tokens":7,"prompt_tokens":45,"total_tokens":52,"prompt_tokens_details":{"cached_tokens":0}}}
HTTP 200

Chat, plain deployment, one text block in a list

curl -sS -w '\nHTTP %{http_code}\n' http://127.0.0.1:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"dbx-qwen35","messages":[{"role":"user","content":[{"type":"text","text":"Reply in JSON with key result set to ok."}]}],"response_format":{"type":"json_object"},"max_tokens":400,"temperature":0}'
{"id":"chatcmpl_...elided","created":1791743713,"model":"dbx-qwen35","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"{\"result\": \"ok\"}","role":"assistant","reasoning_content":"Thinking Process:\n\n1.  **Analyze the Request:**\n    *   Input: \"Reply in JSO...elided"}`\n\n3.  **Validate Constraints:**\n    *   Is it valid JSON? Yes.\n    *   Does it have the key \"result\"? Yes.\n    *   Is the value \"ok\"? Yes.\n    *   Are there any extra keys or text? No, keep it minimal to adhere strictly to the instruction.\n\n4.  **Construct the Final Output:**\n    *   `{\"result\": \"ok\"}`\n\n5.  **Final Review:** Does this meet the user's request exactly? Yes.\n\n6.  **Generate Output.**","thinking_blocks":[{"type":"thinking","thinking":"Thinking Process:\n\n1.  **Analyze the Request:**\n    *   Input: \"Reply in JSO...elided"}`\n\n3.  **Validate Constraints:**\n    *   Is it valid JSON? Yes.\n    *   Does it have the key \"result\"? Yes.\n    *   Is the value \"ok\"? Yes.\n    *   Are there any extra keys or text? No, keep it minimal to adhere strictly to the instruction.\n\n4.  **Construct the Final Output:**\n    *   `{\"result\": \"ok\"
HTTP 200

/v1/responses, one input_text block, json_object text format

curl -sS -w '\nHTTP %{http_code}\n' http://127.0.0.1:$PORT/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"dbx-qwen35","input":[{"role":"user","content":[{"type":"input_text","text":"Reply in JSON with key result set to ok."}]}],"text":{"format":{"type":"json_object"}},"max_output_tokens":400,"temperature":0}'
{"id":"resp_...elided","created_at":1791743717,"error":null,"incomplete_details":null,"instructions":null,"metadata":{},"model":"dbx-qwen35","object":"response","output":[{"type":"reasoning","id":"rs_ecb5344e-2037-44eb-bbcd-bb177fc431c3","status":"completed","role":"assistant","content":[{"type":"output_text","text":"Thinking Process:\n\n1.  **Analyze the Request:**\n    *   Input: \"Reply in JSON with key result set to ok.\"\n    *   Constraint: The output must be in JSON format.\n    *   Specific Requirement: The JSON object must have a key named \"result\" and its value must be \"ok\".\n\n2.  **Determine the Output Format:**\n    *   JSON (JavaScript Object Notation).\n    *   Structure: `{\"result\": \"ok\"}`\n\n3.  **Validate Constraints:**\n    *   Is it valid JSON? Yes.\n    *   Does it have the key \"result\"? Yes.\n    *   Is the value \"ok\"? Yes.\n    *   Are there any extra keys or text? No, keep it minimal to adhere strictly to the instruction.\n\n4.  **Construct the Final Output:**\n    *   `{\"result\": \"ok\"}`\n\n5.  **Final Review:** Does this meet the user's request exactly? Yes.\n\n6.  **Generate Output.**","annotations":[]}],"phase":null},{"type":"message","id"
HTTP 200

/v1/messages, one text block, output_format json_schema

curl -sS -w '\nHTTP %{http_code}\n' http://127.0.0.1:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"dbx-qwen35","max_tokens":60,"messages":[{"role":"user","content":[{"type":"text","text":"Reply in JSON with key result set to ok."}]}],"output_format":{"type":"json_schema","schema":{"type":"object","properties":{"result":{"type":"string"}},"required":["result"]}}}'
{"id":"chatcmpl_...elided","type":"message","role":"assistant","model":"dbx-qwen35","stop_sequence":null,"usage":{"input_tokens":157,"output_tokens":60},"content":[{"type":"thinking","thinking":"Okay, the user asked me to reply in JSON with the key \"result\" set to \"ok\". ...elided","signature":""},{"type":"text","text":""}],"stop_reason":"max_tokens","stop_details":null}
HTTP 200

Chat, AI Gateway route, bridged system.ai model (the reporter's route)

curl -sS -w '\nHTTP %{http_code}\n' http://127.0.0.1:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"gw-llama-responses","messages":[{"role":"user","content":"Reply in JSON with key result set to ok."}],"response_format":{"type":"json_object"},"max_tokens":30}'
{"id":"chatcmpl_...elided","created":1791945637,"model":"gw-llama-responses","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"{\"result\": \"ok\"}","role":"assistant"}}],"usage":{"completion_tokens":7,"prompt_tokens":45,"total_tokens":52,"prompt_tokens_details":{"cached_tokens":0}}}
HTTP 200

Controls, same request to both proxies

request before after what the caller sees
C2: Chat C1 with stream: true 400 400 Databricks rejects stream with json_object on both sides
C5b: /v1/messages C5a with stream: true 200 (stream) 200 (stream) SSE stream of thinking deltas on both sides
C5c: /v1/messages one text block, no output_format 200 200 200 on both sides, thinking block then text
C6a: Chat qwen35, one text block with cache_control, json_object 400 400 400 must contain the word json on both sides, the list stays a list
C6b: Chat qwen35, two text blocks, json_object 400 400 400 must contain the word json on both sides, the list stays a list
C6c: Chat qwen35, text block plus image_url, json_object 400 400 400 image input not supported on both sides
C7x: Chat claude, one text block in a list, json_object, no temperature n/a n/a 200 on both sides with a fenced {"result": "ok"}, the list stays a list
C3: Chat C3b at max_tokens: 60 400 200 400 before, 200 after with null content: Qwen 3.5 spends 60 tokens on reasoning
C4: Responses C4b at max_output_tokens: 60 400 200 400 before, 200 after with status incomplete for the same reason

Control request bodies (same headers and route as above, chat ones to /v1/chat/completions):

C6a: {"model":"dbx-qwen35","messages":[{"role":"user","content":[{"type":"text","text":"Reply in JSON with key result set to ok.","cache_control":{"type":"ephemeral"}}]}],"response_format":{"type":"json_object"},"max_tokens":60,"temperature":0}
C6b: {"model":"dbx-qwen35","messages":[{"role":"user","content":[{"type":"text","text":"Reply in JSON"},{"type":"text","text":" with key result set to ok."}]}],"response_format":{"type":"json_object"},"max_tokens":60,"temperature":0}
C6c: {"model":"dbx-qwen35","messages":[{"role":"user","content":[{"type":"text","text":"Reply in JSON with key result set to ok."},{"type":"image_url","image_url":{"url":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=="}}]}],"response_format":{"type":"json_object"},"max_tokens":60,"temperature":0}
C7x: {"model":"dbx-claude","messages":[{"role":"user","content":[{"type":"text","text":"Reply in JSON with key result set to ok."}]}],"response_format":{"type":"json_object"},"max_tokens":60}

Observed beside the fix, none caused by this PR:

  • Databricks rejects stream with json_object, unchanged
  • Qwen 3.5 reasoning eats a 60-token budget, unchanged
  • json_schema passes Databricks' json check with list content, unchanged
  • Claude Sonnet 5.5 on Databricks rejects temperature, unchanged

/live-pr-risk at 170755a

No breaking change found. Base (96ac1ec) and tip each ran as a 2-worker proxy with its own Postgres on real Databricks, with a forwarding recorder in front of the workspace so the request Databricks received could be diffed. The same 31 requests then ran on the tip merged into current main (083d48f, clean merge), and every status, attempt count, and recorded body matched the tip

request before after
chat, one-block system and user, json_object 400 200
chat, json_object, fallback after a 401 deployment 401 200
chat, mode: responses, json in user 400 200
chat, two one-block system messages, json_object 400 200
AI Gateway system.ai llama, mode: responses 400 200
AI Gateway system.ai gemma, mode: responses 400 200
chat, two text blocks, json_object 400 400
chat, cache_control block, json_object 400 400
chat, "json" only in the system prompt 400 400
chat, one block: plain, stream, tools 200 200
chat, Claude, one block or cache_control 200 200
/v1/messages, one-block system 200 200
/v1/responses, string or message input 200 200

In the recorded Databricks requests, every difference between base and tip is a one-block text list sent as its string, or a run of system messages joined with a blank line. Request keys, other params, and attempt counts are the same on both sides. Claude and cache_control bodies are byte-identical

  • Breaking: none observed
  • Backward incompatible: what non-Claude Databricks models receive, as listed in Caveats. The author kept it on purpose, see the TLDR paragraph and commit ec4d6ee
  • Regression risk: an endpoint serving Claude under a name without "claude" now gets string content. Databricks Claude answered string content with 200 on both sides, and cache_control blocks stay lists
  • Dependency graph, all verified live: chat, the Responses bridge, mode: responses, /v1/messages, router fallback, the system-message merge, the parallel tool-call split, and /utils/transform_request, which now shows the string
  • Not verified: the reporter's exact AI Gateway model, which our workspace lacks, and the raw_request attribute in OTel or Langfuse logs, which changes shape the same way

Suites at the tip: tests/llm_translation/test_databricks.py, test_prompt_factory.py, tests/unit/llms/databricks, and the bridge flag test gave 213 passed and 2 skipped

/audit round 1 of 3, PASS

Cell Base 96ac1ec Head 170755a Head again
C1 two one-block system red green green
C2 system then developer red green green
C3 one-block then string system red green green
C4 cache_control system stays parts green green green
C5 parallel tool results red green green
F1 extra keys, blank, 5 KB red green green
Responses instructions join red green green
Router fallback red green green
OpenAI SDK sync, spend row red green green
OpenAI SDK async stream red green green
Anthropic SDK stream red green green
Burst through an upstream outage red red, flake green
/utils/transform_request red green green
Non-string text rejected green green green

Every cell is a test in tests/integration/providers/test_databricks_chat_wire.py from d794863. Each leg ran a 2-worker proxy at its commit with its own Postgres and Redis and a scripted Databricks upstream, 4 test workers like the providers group in CI, seed 4106601. Base and the first head run went side by side as lanes audit1f-base and audit1f-head-run1, and the second head run as audit1f-head-run2. C4 and the non-string cell are expected to match on both sides, since neither shape changes

The burst cell's one red was a 15 s client timeout while one proxy worker stopped serving for about 40 s right after its first Hugging Face tokenizer load. That code is not in this diff and the base has it too. The cell passed on the second run and again on freshly started proxies (audit1g), so it is a Low caveat. The live rows are the Before, After, and /live-pr-risk runs above at 170755a

Tests

Added in tests/unit/llms/databricks/chat/test_databricks_chat_transformation.py: test_transform_request_collapses_single_plain_text_block_for_non_claude_models, one parametrized test that runs transform_request and asserts the whole outgoing messages value

  • user, system, assistant, tool: a one-block [{"type": "text", "text": ...}] content on a non-Claude model goes out as a plain string
  • cache-control, multiple-text-blocks, text-and-image: the content stays the same list
  • plain-string: string content stays a string
  • claude: a one-block text list on a Claude model stays a list

Added in tests/integration/providers/test_databricks_chat_wire.py: a real proxy with a scripted Databricks upstream, asserting the exact messages the upstream receives

  • test_databricks_non_claude_single_text_block_reaches_upstream_as_string: A1 chat non-stream, A2 chat stream, A3 a model_info.mode: responses deployment with string content (the reported case), A3b the same with the customer's system.ai.deepseek-v4-1-flash name, which goes to the AI Gateway path /ai-gateway/mlflow/v1/chat/completions, A4 /v1/messages, A5 /v1/responses with an input_text list. Each one reaches Databricks as a plain string
  • test_databricks_list_content_stays_list: B1 cache_control block, B2 two text blocks, B3 text plus image, B4 Claude. Each one reaches Databricks as the same list

Added by /audit in the same file: 14 cells covering system-message joins (C1 to C5), malformed and 5 KB blocks (F1), the Responses bridge with instructions, router fallback, the OpenAI SDK sync and async stream, the Anthropic SDK stream, a burst through an upstream outage, /utils/transform_request, and a non-string text block. Each asserts what the caller got and the exact messages the scripted upstream received

Changed in tests/unit/responses/test_responses_api_bridge_flag.py: test_bridge_merges_instructions_and_developer_input_for_databricks from #42390 now expects plain strings, "You are terse.\n\nSkills: none." for the merged system message and "Hello" for the user message. It used to pin the one-block lists this PR removes. The system-message merge it was written for still holds

Removed: none

Mutation check: with the collapse removed, the 4 collapse unit cases fail and the 5 list cases still pass. On the merge base, A1 to A5 fail and B1 to B4 pass

Type

🐛 Bug Fix
✅ Test

Caveats (if any)

Medium

  • Two or more text blocks, an image, or a cache_control block with json_object still get the 400
    • Databricks reads "json" only from string content, on main and here
    • A cache_control block stays a list on purpose, so the marker is never dropped without a decision
    • Workaround: send the text as one string, or use json_schema. A fix is tracked separately

Low

  • Two or more one-block system messages now reach the model as one joined string
    • This is the Codex shape, instructions plus a developer message
    • On Llama 4 Maverick the list dropped the second message, 34 prompt tokens. Now it arrives, 39 tokens, the same as two string system messages on main
    • Replies from those models can change
  • Every non-Claude one-block text content now goes out as a string
    • This holds with or without json_object
    • Both shapes gave the same prompt tokens on llama-3.3-70b and qwen3-next
  • The reporter's exact AI Gateway model was not called live
    • Our workspace has no system.ai.deepseek-v4-1-flash
    • system.ai.meta-llama-3-3-70b-instruct on the same route went from 400 to 200, see Before and After
  • Databricks gpt models with mode: responses still fail, on main and here
    • They go to Databricks' native Responses API, which rejects them
  • Databricks rejects stream: true with json_object on main and here
  • model_info.mode: responses leaks to same-model deployments, tracked in LIT-9393
  • The outage-burst integration cell timed out once on the tip
    • One proxy worker stalled about 40 s after its first Hugging Face tokenizer load, code this PR does not touch
    • It passed on the next run and on fresh proxies, and the stall is tracked on its own ticket

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Link to Devin session: https://app.devin.ai/sessions/d5715e574f4b43cca4f20f56de48f29c
Open in Devin Desktop: https://app.devin.ai/desktop/session/d5715e574f4b43cca4f20f56de48f29c?variant=devin
Requested by: @mrinal-berri

Link to Devin session: https://app.devin.ai/sessions/3c3db96b0d7240afab791f78f2e428fc
Open in Devin Desktop: https://app.devin.ai/desktop/session/3c3db96b0d7240afab791f78f2e428fc?variant=devin


Note

Medium Risk
Changes the wire shape of all non-Claude Databricks prompts (not only json_object), which can alter model behavior for multi-part system messages; Claude and multi-block content paths are explicitly preserved.

Overview
Fixes Databricks json_object failures when user content is a one-item text list: upstream only scans string content for the word "json", so list-shaped prompts were rejected even when the text said "JSON".

Databricks chat transformation now collapses a lone [{"type": "text", "text": "..."}] block to a plain string for non-Claude models on every outbound request (chat, /v1/messages, /v1/responses bridge, AI Gateway routes). Claude on Databricks is unchanged. Lists are kept when there are multiple blocks, cache_control, images, or extra keys on the block.

Collapse runs before consecutive system/developer messages are merged, so multiple one-block system turns join into one string with blank lines—the Responses bridge test expectation is updated accordingly.

Coverage adds unit tests on transform_request, broad wire/integration tests (SDKs, fallback, burst, /utils/transform_request), and a regression case for non-string text values.

Reviewed by Cursor Bugbot for commit 0f4f923. Bugbot is set up for automated code reviews on this repo. Configure here.

mrinal-berri and others added 5 commits October 9, 2026 19:14
…laude models

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@greptile-apps

greptile-apps Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no remaining actionable findings.

Summary

Databricks non-Claude models now receive a single plain text block as a string, fixing the reported JSON-mode error.

  • Databricks sends a lone text block as a string for non-Claude models.

Reviews (5) · Last reviewed commit: "test(databricks): assert the whole outgo..." · Reviewed by Greptile

@codspeed

codspeed Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 31 untouched benchmarks


Comparing litellm_databricks_single_text_block_as_string (0f4f923) with main (b37eac2)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (b22a0bd) during the generation of this report, so b37eac2 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@codecov

codecov Bot commented Oct 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…essages

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

@greptileai

@mrinal-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@mrinal-berri

Copy link
Copy Markdown
Contributor Author

@greptile review, live proof has been given in PR desc

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

mrinal-berri and others added 2 commits October 10, 2026 05:50
…ngle_text_block_as_string

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

# Conflicts:
#	tests/integration/providers/test_databricks_chat_wire.py
…and #45618

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mrinal-berri

Copy link
Copy Markdown
Contributor Author

@greptileai review

@mrinal-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Devin is archived and cannot be woken up. Please unarchive Devin if you want to continue using it.

View session

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

mrinal-berri and others added 2 commits October 10, 2026 17:32
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…apse unit test

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

@greptileai review

@mrinal-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@tonydzi tonydzi left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mycroft here, Anton's synthetic co-founder; I bring a measurement, not a preference

I put this head and #45713 on one wire-form stand and posted the full matrix in #45618 rather than repeat it here. Two things that are specific to this patch, both from the same run (respx capture, upstream mocked, no keys, each head on its own merge-base, both bases byte-identical to main)

  1. The radius reaches requests that never touched the bridge. Because _collapse_single_text_block is applied inside _transform_messages, on the new_messages.append(...) line your diff rewrites (litellm/llms/databricks/chat/transformation.py:480 on main), a plain /chat/completions call with messages=[{"role":"user","content":[{"type":"text","text":"Reply in JSON"}]}] now serialises as {"role":"user","content":"Reply in JSON"}. #45713, fixing the bridge instead, leaves that request byte-identical to main. This is not an objection, the issue can be read either way, but the two patches cover different sets of requests and neither contains the other, so it is worth stating which set is intended

  2. The head also has to rewrite an existing test, and the reason is not visible in the diff alone. The collapse turns on a second, unrelated code path in the system-message merge, so main's own test for the bridge's instructions + developer pair stops matching and is updated here to the joined form. That is a defensible choice, but it means the guarded behaviour changed rather than the test having been wrong. The mechanism, the file:line and the cross-suite numbers are in #45618 so they are in one place for both heads

No real Databricks call was made here, so what the endpoint accepts is taken from the issue text; the live-proxy proof stays with the maintainers. Your own new tests under tests/integration/providers and tests/unit/llms/databricks were outside the two paths I cross-ran and are not covered by the numbers above

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@litereview

litereview Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

✅ code-review

5/5 · Ready for human review

Scope: full · Full PR review.

Completed · Some checks not run.

No correctness findings.

Checks and execution details
  • Passed · Real testing evidence (required): In scope: the PR changes request message translation in litellm/llms/databricks/chat/transformation.py. For non-Claude models, _collapse_single_text_block sends a single plain text block as a string.

Evidence that qualifies: the PR description includes inspectable manual E2E results against a real Databricks Azure workspace. It ran an A/B test between the merge base 96ac1ec and the product tip 170755a. Head 0f4f923e is described as a clean merge of main with the same product diff. The results include exact curl commands and the proxy config: dbx-llama70b-responses with mode: responses, plain dbx-qwen35, dbx-claude, and the AI Gateway system.ai route. They also show the observed status and body for each request.

The results cover the changed behavior and its controls:

  • Fixed (400 → 200): a one-block list, mode: responses, /v1/responses input_text, and a run of system messages.
  • Unchanged: blocks with cache_control, multiple text blocks, a text block with image_url, and Claude.

A recording proxy diffed the request bodies Databricks received.

Supporting tests: wire-level integration tests in tests/integration/providers/test_databricks_chat_wire.py assert the outgoing request shape against a local stub. They support the fix but are not the basis for passing this check.

  • Passed · Unit tests for Databricks transformation and the Responses bridge (optional): I ran uv run --frozen --all-extras pytest tests/unit/llms/databricks/chat/test_databricks_chat_transformation.py tests/unit/responses/test_responses_api_bridge_flag.py -q, and all 102 tests passed. Without --all-extras, two tests failed because the mcp module was missing. That came from my local setup, not the PR.
  • Not run · Integration wire tests (tests/integration/providers/test_databricks_chat_wire.py) (optional): I did not run these tests because the harness needs the integration Postgres/Redis worker stack, which is not available in this sandbox. The real Databricks evidence above covers the same behavior.
  • Passed · Code trace of the collapse and the system-message merge (optional): _collapse_single_text_block collapses content only when it equals exactly [{"type":"text","text":&lt;str>}]. Blocks with extra keys such as cache_control stay lists. The collapse runs before merge_consecutive_system_messages, so the system messages in a run become strings and _merge_system_message_run joins them with \n\n. The PR describes this join, and the updated bridge test expects it. Claude models skip the collapse. I found no API or config incompatibility that would need a breaking-change marker.

View review · Reviewed 0f4f923e5478

@mateo-berri

Copy link
Copy Markdown
Contributor

The Databricks-layer set is intended: a direct chat call with a one-block list hits the same 400, which a bridge-only fix leaves broken

@mateo-berri

Copy link
Copy Markdown
Contributor

@mrinal-berri ok if I push one tests-only commit here with more Databricks integration cells (system message join, fallback, SDK clients) before merging?

Copy link
Copy Markdown
Contributor Author

yes absolutely

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor

@mrinal-berri the required lint check now needs a script that only main has. Ok if I merge main into this branch so it can pass?

@mrinal-berri

Copy link
Copy Markdown
Contributor Author

Yes

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 0f4f923. Configure here.

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@mateo-berri
mateo-berri merged commit 1aee1a2 into main Oct 14, 2026
95 of 96 checks passed
@mateo-berri
mateo-berri deleted the litellm_databricks_single_text_block_as_string branch October 14, 2026 09:22
pamanseau pushed a commit to KubeTEE-AI/litellm that referenced this pull request Oct 25, 2026
…laude models (BerriAI#45686)

Backport of BerriAI#45686 to stable/1.103.x.
Cherry-picked from 1aee1a2 (main).
Adapted to the line: unit test ported into tests/test_litellm; the databricks wire-test additions and the bridge-flag test edit are dropped since neither base test is on this line.
Cartofante pushed a commit to CartoDB/litellm that referenced this pull request Oct 26, 2026
…laude models (BerriAI#45686)

Backport of BerriAI#45686 to stable/1.106.x.
Cherry-picked from 1aee1a2 (main).
haowang1013 pushed a commit to directivegames/litellm that referenced this pull request Nov 3, 2026
…laude models (BerriAI#45686)

Backport of BerriAI#45686 to stable/1.105.x.
Cherry-picked from 1aee1a2 (main).
Test-file import conflict resolved by keeping the line's imports plus this PR's own.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants