Skip to content

ChatAnthropic rejects supported mid-conversation system messages #11472

Description

Example Code

import { ChatAnthropic } from "@langchain/anthropic";
import { HumanMessage, SystemMessage } from "@langchain/core/messages";

const model = new ChatAnthropic({ model: "claude-opus-5" });

await model.invoke([
  new SystemMessage("You are a coding assistant."),
  new HumanMessage("Update this project."),
  new SystemMessage("Follow the project README."),
]);

Error Message

Error: System messages are only permitted as the first passed message.

Description

Anthropic supports role: "system" messages after a user turn on recent models, but ChatAnthropic rejects them before sending the request.

The first SystemMessage should continue to use the top-level system field. Later SystemMessage instances should remain in messages with role: "system".

Anthropic docs: https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages

Related Python issue: langchain-ai/langchain#38651

System Info

  • @langchain/anthropic: 1.5.8
  • @langchain/core: 1.2.9
  • Node.js: 22.22.3
  • pnpm: 10.30.3
  • macOS: 26.5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions