Skip to content

AnthropicLanguageModel sends session instructions as a user message instead of top-level system #431

Closed

Description

@shura-v

On AnyLanguageModel 1.3.0, an .instructions entry is sent to Anthropic's Messages API as the first user message. The text arrives, but the model receives it as something the user said rather than as an application instruction.

Reproduction

With an AnthropicLanguageModel and a recording HTTPTransport, inspect the body of the first non-streaming POST /v1/messages. No live API key or model response is needed to see the difference:

let history = Transcript(entries: [
    .instructions(.init(
        segments: [.text(.init(content: "Answer in French."))],
        toolDefinitions: []
    ))
])
let session = LanguageModelSession(model: model, transcript: history)
_ = try await session.respond(to: "Hello!")

Actual (relevant fields): system is absent. messages starts with a user message containing Answer in French., followed by the actual user prompt Hello!.

Expected: the instruction appears once in the top-level system field, and messages starts with Hello!. Anthropic uses a top-level field, not a system role inside messages.

This was observed in the outgoing request on 1.3.0. The same mapping is still present on main: the request builder receives system: nil, and .instructions is converted to .user. Related precedent for MLX: #47.

Activity

  1. mattt commented on Nov 20, 2026

    @mattt
    Collaborator

    Hi @shura-v. Thanks for the clear report and reproduction! This is fixed in 1.4.1: AnthropicLanguageModel now sends instructions in the top-level system field (#433). GeminiLanguageModel had the same problem, and that's fixed too (#436).

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

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