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
Example Code
Error Message
Description
Anthropic supports
role: "system"messages after a user turn on recent models, butChatAnthropicrejects them before sending the request.The first
SystemMessageshould continue to use the top-levelsystemfield. LaterSystemMessageinstances should remain inmessageswithrole: "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