Skip to content

BUG: Claude Code 2.1.215 embedded system messages fail validation #255

Description

@SimianW

Kiro Gateway Version

Current main at a5292ca (v2.4 development branch)

What happened?

Claude Code v2.1.215 can place runtime system reminders in messages[] using role: "system". Kiro Gateway rejects the request during Pydantic validation because AnthropicMessage.role only accepts user and assistant.

Minimal sanitized request shape:

{
  "model": "<model-id>",
  "messages": [
    {"role": "user", "content": "<redacted>"},
    {
      "role": "system",
      "content": [
        {
          "type": "text",
          "text": "<runtime instructions redacted>",
          "cache_control": {"type": "ephemeral"}
        }
      ]
    }
  ],
  "system": [{"type": "text", "text": "<base system prompt redacted>"}]
}

The request never reaches the converter or Kiro runtime. A standard request through the same endpoint succeeds.

Expected behavior: before validating conversation roles, the Anthropic compatibility layer should preserve embedded system content by merging it into the top-level system field and remove those entries from messages[]. The same normalization should apply to /v1/messages/count_tokens.

Debug Logs

Sanitized validation output:

Validation error (422): [{
  "type": "literal_error",
  "loc": ["body", "messages", 1, "role"],
  "msg": "Input should be 'user' or 'assistant'",
  "input": "system"
}]

No prompts, tool definitions, credentials, account identifiers, local paths, or raw debug files are included.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions