AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

ChatAnthropic Sends Assistant Prefill For Models That Don'T Support It

ChatAnthropic incorrectly includes a trailing AIMessage in the Anthropic request payload, causing a 400 error for models like claude-opus-4-6 that do not support assistant message prefill.

highConfidence 85%Langchain-AnthropicChat ModelsEmbeddingsRetrieversAffected V1.0.4

Origin Analysis

The `_format_messages` method in langchain_anthropic does not validate whether the final message in the conversation is an assistant message for models that disallow prefill, so it passes the trailing AIMessage directly to the Anthropic API as assistant prefill.
1. Install langchain-anthropic 1.0.4 and anthropic 0.73.0. 2. Instantiate ChatAnthropic(model='claude-opus-4-6'). 3. Invoke with [HumanMessage(content='how are you'), AIMessage(content="I'm doing well, thanks for asking!")]. 4. Observe anthropic.BadRequestError with message 'This model does not support assistant message prefill.'

Fixing Code Block

Edge Case Audit

This hotfix only covers models listed in NON_PREFILL_MODELS; future models with the same restriction must be added manually. It raises an error rather than stripping the message, so users must restructure their prompts to end with a human message. If you prefer to strip the trailing assistant message automatically, modify the patch to remove the last element instead of raising, but that may discard context. Rollback by removing the monkey patch or restoring the original method.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state