fix(anthropic): replace whitespace-only trailing user message with non-whitespace character#6215
Open
tsushanth wants to merge 1 commit into
Open
Conversation
…n-whitespace character inject_trailing_user_message appends a dummy user turn when the chat context ends on an assistant message, to satisfy Claude 4.6+ models that reject prefilling. The placeholder text was a single ASCII space, which Anthropic's Messages API rejects with HTTP 400 (messages: text content blocks must contain non-whitespace text). Replace the space with a period so the structural intent of the dummy turn is preserved while satisfying the API's non-whitespace requirement. Fixes livekit#5254 Fixes livekit#6213
|
|
longcw
approved these changes
Jun 25, 2026
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.
Fixes #5254
Fixes #6213
to_chat_ctxin_provider_format/anthropic.pyappends a trailing user turn wheninject_trailing_user_message=Trueand the chat context ends on an assistant message. This path is taken for models matched by_NO_PREFILL_PATTERNS(currentlyclaude-sonnet-4-6andclaude-opus-4-6) to satisfy their no-prefill constraint.The placeholder text was a single ASCII space (
" "), which Anthropic's Messages API rejects:This fails every LLM call that goes through the no-prefill branch when the context ends on an assistant turn — common in sequential
generate_reply()calls, agent handoffs, and silence re-engagement flows.The fix replaces the single space with a period. The structural intent (forcing a user turn) is preserved; the one-character change is the minimal-blast-radius fix that satisfies the API constraint.