fix(anthropic): use non-whitespace trailing dummy to satisfy provider validation#6216
Open
JasonGordonD wants to merge 1 commit into
Open
Conversation
…space placeholder The trailing user message injected for Claude 4.6+ (which does not support prefilling) used a single space, which Anthropic's API rejects with: HTTP 400 invalid_request_error "messages: text content blocks must contain non-whitespace text" This stalled any LiveKit agent on claude-sonnet-4-6 / claude-opus-4-6 whenever the chat_ctx ended on an assistant turn (sequential generate_reply, agent handoff, etc.). Use "." instead — minimal-blast-radius placeholder that preserves the intent of PR livekit#4973 while satisfying Anthropic's validator. Refs: livekit#6213 Related: livekit#4973, livekit#4907
|
|
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
One-line fix in
livekit-agents/livekit/agents/llm/_provider_format/anthropic.py: the trailing dummy user message injected when the last message is from the assistant now uses"."instead of" "(a single non-whitespace character instead of whitespace).Why
Anthropic's API rejects messages whose text content is empty or whitespace-only. When
inject_trailing_user_message=Trueappends a placeholder user turn to satisfy Claude 4.6+'s no-prefilling requirement, the current" "(single space) trips Anthropic's server-side validation and the request fails before the model is ever reached. Replacing it with"."keeps the placeholder semantically inert while clearing the validation gate.Relationship to existing issues
This addresses #5254, which was closed as stale. The bug still reproduces verbatim on current
main(1.6.3) — any conversation that ends with an assistant turn and is then re-submitted to the Anthropic provider hits the same validation error described in the original report.Requesting reopen of #5254 and merge of this fix.
Change
That is the entire diff.