Skip to content

fix(anthropic): use non-whitespace trailing dummy to satisfy provider validation#6216

Open
JasonGordonD wants to merge 1 commit into
livekit:mainfrom
JasonGordonD:fix/anthropic-trailing-dummy-non-whitespace
Open

fix(anthropic): use non-whitespace trailing dummy to satisfy provider validation#6216
JasonGordonD wants to merge 1 commit into
livekit:mainfrom
JasonGordonD:fix/anthropic-trailing-dummy-non-whitespace

Conversation

@JasonGordonD

Copy link
Copy Markdown

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=True appends 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

-        messages.append({"role": "user", "content": [{"text": " ", "type": "text"}]})
+        messages.append({"role": "user", "content": [{"text": ".", "type": "text"}]})

That is the entire diff.

…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
@JasonGordonD JasonGordonD requested a review from a team as a code owner June 24, 2026 17:58
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants