Skip to content

fix(anthropic): send placeholder for empty assistant turns instead of dropping - #421

Open
cpsievert wants to merge 2 commits into
mainfrom
fix-anthropic-empty-assistant-turn
Open

fix(anthropic): send placeholder for empty assistant turns instead of dropping#421
cpsievert wants to merge 2 commits into
mainfrom
fix-anthropic-empty-assistant-turn

Conversation

@cpsievert

Copy link
Copy Markdown
Collaborator

Closes #416.

AnthropicProvider._as_message_params dropped assistant turns with zero content blocks, which could produce two consecutive user messages and violate Anthropic's user/assistant alternation requirement. Now sends an [empty string] placeholder instead, matching ellmer's fix (tidyverse/ellmer#1099, tidyverse/ellmer#1100) and chatlas's existing empty-text normalization in _content.py.

Also audited other providers for a similar drop-empty-turn pattern — none exists; the fix is Anthropic-only. The outdated test asserting the dropping behavior was replaced with one asserting the placeholder.

… dropping

Dropping an empty assistant turn could produce two consecutive user
messages, violating the API's user/assistant alternation requirement.
Send an '[empty string]' placeholder instead, matching ellmer's fix
(tidyverse/ellmer#1099) and chatlas's existing empty-text normalization.

Closes #416
@cpsievert
cpsievert force-pushed the fix-anthropic-empty-assistant-turn branch from c3c1ac7 to 068df80 Compare September 4, 2026 00:52
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.

Anthropic provider drops empty assistant turns, breaking role alternation

1 participant