Repository navigation
fix(databricks): send a single plain text block as a string for non-Claude models - #45686
Conversation
…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>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Merging this PR will not alter performance
|
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>
|
bugbot run |
|
@greptile review, live proof has been given in PR desc |
…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>
|
@greptileai review |
|
bugbot run |
|
Devin is archived and cannot be woken up. Please unarchive Devin if you want to continue using it. |
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>
|
@greptileai review |
|
bugbot run |
tonydzi
left a comment
There was a problem hiding this comment.
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)
-
The radius reaches requests that never touched the bridge. Because
_collapse_single_text_blockis applied inside_transform_messages, on thenew_messages.append(...)line your diff rewrites (litellm/llms/databricks/chat/transformation.py:480onmain), a plain/chat/completionscall withmessages=[{"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 tomain. 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 -
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'sinstructions+developerpair 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
|
@litereview code-review |
✅ code-review5/5 · Ready for human reviewScope: full · Full PR review. Completed · Some checks not run. No correctness findings. Checks and execution details
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 The results cover the changed behavior and its controls:
A recording proxy diffed the request bodies Databricks received. Supporting tests: wire-level integration tests in
View review · Reviewed |
|
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 |
|
@mrinal-berri ok if I push one tests-only commit here with more Databricks integration cells (system message join, fallback, SDK clients) before merging? |
…ge burst for one-block content
|
yes absolutely |
|
@litereview code-review |
|
bugbot run |
|
@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? |
|
Yes |
…ngle_text_block_as_string
|
@litereview code-review |
|
bugbot run |
There was a problem hiding this comment.
✅ 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.
…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.
…laude models (BerriAI#45686) Backport of BerriAI#45686 to stable/1.106.x. Cherry-picked from 1aee1a2 (main).
…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.
TLDR
Problem this solves:
json_object400s with "must contain the word json"model_info.mode: responsesdeployments always send that list shapeHow it solves it:
cache_control, images, or several blocks stay listsThe fix lives in the Databricks layer, not the bridge, because a direct
/v1/chat/completionscall 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 withresponse_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: responsesgets a 400 in JSON mode even though their prompt says "JSON""content": "Reply in JSON with key a. hi"and"response_format": {"type": "json_object"}"messages" must contain the word "json" in some form, to use "response_format" of type "json_object"[{"type": "text", ...}]list to a plain Databricks deployment fails the same wayAfter: the same requests succeed and return JSON
{"a": "hi"}as the message contentRelevant issues
Fixes #45618
Linear ticket
Resolves LIT-9393
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
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 moreDelays 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-responsesisdatabricks/databricks-meta-llama-3-3-70b-instructwithmodel_info.mode: responses(the reported setup),dbx-qwen35is a plaindatabricks/databricks-qwen35-122b-a10bdeployment,dbx-claudeisdatabricks/databricks-claude-sonnet-5-5.gw-llama-responsesisdatabricks/system.ai.meta-llama-3-3-70b-instructwithmodel_info.mode: responses, which goes out on Databricks' AI Gateway route/ai-gateway/mlflow/v1/chat/completionslike 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 editedBefore (96ac1ec)
Chat, bridged deployment, string content (the reported case)
Chat, plain deployment, one text block in a list
/v1/responses, one input_text block, json_object text format
/v1/messages, one text block, output_format json_schema
Chat, AI Gateway route, bridged
system.aimodel (the reporter's route)After (170755a)
Chat, bridged deployment, string content (the reported case)
Chat, plain deployment, one text block in a list
/v1/responses, one input_text block, json_object text format
/v1/messages, one text block, output_format json_schema
Chat, AI Gateway route, bridged
system.aimodel (the reporter's route)Controls, same request to both proxies
stream: truestreamwithjson_objecton both sidesstream: truecache_control, json_object{"result": "ok"}, the list stays a listmax_tokens: 60max_output_tokens: 60Control request bodies (same headers and route as above, chat ones to
/v1/chat/completions):Observed beside the fix, none caused by this PR:
/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
mode: responses, json in usersystem.aillama,mode: responsessystem.aigemma,mode: responsescache_controlblock, json_objectcache_control/v1/messages, one-block system/v1/responses, string or message inputIn 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_controlbodies are byte-identicalcache_controlblocks stay listsmode: responses,/v1/messages, router fallback, the system-message merge, the parallel tool-call split, and/utils/transform_request, which now shows the stringraw_requestattribute in OTel or Langfuse logs, which changes shape the same waySuites 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
cache_controlsystem stays partsinstructionsjoin/utils/transform_requesttextrejectedEvery cell is a test in
tests/integration/providers/test_databricks_chat_wire.pyfrom 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 lanesaudit1f-baseandaudit1f-head-run1, and the second head run asaudit1f-head-run2. C4 and the non-string cell are expected to match on both sides, since neither shape changesThe 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 170755aTests
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 runstransform_requestand asserts the whole outgoingmessagesvalueuser,system,assistant,tool: a one-block[{"type": "text", "text": ...}]content on a non-Claude model goes out as a plain stringcache-control,multiple-text-blocks,text-and-image: the content stays the same listplain-string: string content stays a stringclaude: a one-block text list on a Claude model stays a listAdded in
tests/integration/providers/test_databricks_chat_wire.py: a real proxy with a scripted Databricks upstream, asserting the exactmessagesthe upstream receivestest_databricks_non_claude_single_text_block_reaches_upstream_as_string: A1 chat non-stream, A2 chat stream, A3 amodel_info.mode: responsesdeployment with string content (the reported case), A3b the same with the customer'ssystem.ai.deepseek-v4-1-flashname, which goes to the AI Gateway path/ai-gateway/mlflow/v1/chat/completions, A4/v1/messages, A5/v1/responseswith aninput_textlist. Each one reaches Databricks as a plain stringtest_databricks_list_content_stays_list: B1cache_controlblock, B2 two text blocks, B3 text plus image, B4 Claude. Each one reaches Databricks as the same listAdded 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-stringtextblock. Each asserts what the caller got and the exactmessagesthe scripted upstream receivedChanged in
tests/unit/responses/test_responses_api_bridge_flag.py:test_bridge_merges_instructions_and_developer_input_for_databricksfrom #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 holdsRemoved: 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
cache_controlblock withjson_objectstill get the 400cache_controlblock stays a list on purpose, so the marker is never dropped without a decisionjson_schema. A fix is tracked separatelyLow
instructionsplus adevelopermessagejson_objectsystem.ai.deepseek-v4-1-flashsystem.ai.meta-llama-3-3-70b-instructon the same route went from 400 to 200, see Before and Aftergptmodels withmode: responsesstill fail, on main and herestream: truewithjson_objecton main and heremodel_info.mode: responsesleaks to same-model deployments, tracked in LIT-9393Final Attestation
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_objectfailures 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/responsesbridge, 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-stringtextvalues.Reviewed by Cursor Bugbot for commit 0f4f923. Bugbot is set up for automated code reviews on this repo. Configure here.