Drop empty ContentText in OpenAI-compatible serialization#935
Open
JamesHWade wants to merge 2 commits intotidyverse:mainfrom
Open
Drop empty ContentText in OpenAI-compatible serialization#935JamesHWade wants to merge 2 commits intotidyverse:mainfrom
JamesHWade wants to merge 2 commits intotidyverse:mainfrom
Conversation
) Databricks returns `content: ""` for tool-only assistant turns, which creates `ContentText("")` objects. When replayed, these empty text blocks cause HTTP 400 errors. Filter out empty ContentText during as_json() serialization, following the existing pattern from the Claude provider. Closes tidyverse#932 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
hadley
reviewed
Feb 28, 2026
R/provider-openai-compatible.R
Outdated
| contents <- x@contents[!is_empty_text] | ||
| if (length(contents) == 0) { | ||
| # Drop empty assistant turns to avoid an API error | ||
| return(list()) |
Member
There was a problem hiding this comment.
I think this should probably be a NULL?
| )) | ||
| ) | ||
|
|
||
| # Empty ContentText is stripped but tool requests are preserved |
Member
There was a problem hiding this comment.
This should be a separate test I think
| content = list(list(type = "text", text = "Hello")) | ||
| )) | ||
| ) | ||
|
|
Member
There was a problem hiding this comment.
I think you're missing a test for the (length(contents) == 0) case? i.e. something like list(ContentText(""), ContentText("")). I'd also like to see a live test for that because my recollection from doing this work on Claude is that will cause a problem.
- In value_turn(), treat content: "" as content: null so ContentText("")
is never created from provider responses (root cause fix)
- Change return(list()) to return(NULL) for empty assistant turns
- Split tool request test into its own test_that()
- Add test for multiple empty ContentText values
- Add test that value_turn() preserves tool requests when dropping empty text
- Add live Databricks test for continuing chat after empty assistant content
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
|
Thanks for the review! Addressed all three points:
Also fixed the root cause: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
chat_databricks()HTTP 400 errors when conversation history contains emptyContentText("")objects, which occur during tool calling when Databricks returnscontent: ""instead ofcontent: nullContentTextduringas_json()serialization forProviderOpenAICompatible, following the existing pattern from the Claude providerCloses #932
Test plan
ContentTextis dropped during serializationContentText(dropped entirely)🤖 Generated with Claude Code