Repository navigation
fix(databricks): join plain text blocks for non-Claude json_object requests - #46436
mateo-berri wants to merge 3 commits into
Conversation
Merging this PR will not alter performance1 warning
Comparing |
|
@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
View review · Reviewed |
|
bugbot run |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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 29647eb. Configure here.
|
Superseded by #49385, which carries the same fix and proof forward. Closing this copy so review happens in one place |
TLDR
Problem this solves:
json_object400s with "must contain the word json"How it solves it:
json_objectrequests join plain text blocks into one stringcache_control, images, or extra keys stay listsjson_objectare unchangedDesign notes
Databricks only looks for the word "json" in string content, so list content fails in JSON mode however the text is split. The join only runs for
response_format: {"type": "json_object"}on non-Claude models, where the list form always 400s today, so no request that works now changes shape. A join on every request, like the single block collapse in #45686, was rejected because models read a multi-block list differently. Gemma 3 12B and Llama 4 Maverick on Databricks read it as one run of text, while Llama 3.3 70B and gpt-oss-120b put a space between blocks, so a global join could change the prompt of working requestsThe blocks join with an empty string. OpenAI reads a list of text blocks as concatenated text (gpt-5.4-mini echoed
XQ7ZK9for the blocksXQ7andZK9), andconvert_content_list_to_stralready joins the same way, so Databricks gets the prompt the caller wrote for OpenAI. A newline or space separator was rejected because it adds characters the caller never sent. Injecting the word "json" into the prompt was rejected because it changes what the model readsThe join runs per message before consecutive system messages are merged, so two system messages keep the blank line between them. Joining after the merge would glue them into one run of text. A text block that carries
cache_controlor any other extra key, or a list with an image, stays a list, so a cache marker is never dropped silentlyThe empty text block filter now reads blocks through the same typed path. One edge changes there: a text block whose
textis a truthy non-string used to raiseAttributeErrorand is now kept as isUser Flow
Before: a developer whose app builds its prompt from several text parts gets a 400 in JSON mode from a Databricks model
json_objectand two text parts"messages" must contain the word "json" in some forminput_textto POST https://litellm-domain/v1/responses withjson_objectget the same 400After: the same requests succeed and come back as JSON
json_object{"result": "ok"}as the message content{"result": "ok"}as its output textPre-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
Shared setup, config and client
These are live runs against real Databricks serving endpoints with curl, the client from the original report. Each leg is one proxy process with
--num_workers 2and no database, booted from the config below, with the same requests on both legs. Long lines are cut at 1500 characters./v1/messagesis not a case because the Anthropic Messages API has nojson_objectmode, so no request there reaches the changed coderesponse_formatjson_schemaBefore (aa0279e)
Chat completions, Llama 3.3 70B, two text parts
Send the request
Observed response
Chat completions, Qwen 3.5, two text parts
Steps and output
Send the request
Observed response
Responses, Llama 3.3 70B, two input_text parts
Steps and output
Send the request
Observed response
Chat completions streaming, Qwen 3.5, two text parts
Steps and output
Send the request
Observed response
After (29647eb)
Chat completions, Llama 3.3 70B, two text parts
Send the request
Observed response
Chat completions, Qwen 3.5, two text parts
Steps and output
Send the request
Observed response
Responses, Llama 3.3 70B, two input_text parts
Steps and output
Send the request
Observed response
Chat completions streaming, Qwen 3.5, two text parts
Steps and output
Send the request
Observed response
The Qwen 3.5 reasoning quotes the prompt as "Reply in JSON with key result set to ok.", so the parts are joined exactly as written
Observations from the run
json_object400s on both legs, even with one stringstreamtogether withjson_objectupstreammax_tokens, returning null content{"result": "ok"}Type
🐛 Bug Fix
✅ Test
Final Attestation
Bugbot summary