Skip to content

Recognize all Claude model ids in encode_prompt - #11

Merged
wmeddie merged 1 commit into
bedrock-model-fallbackfrom
fix/encode-prompt-claude4-models
Jun 26, 2026
Merged

wmeddie merged 1 commit into
bedrock-model-fallbackfrom
fix/encode-prompt-claude4-models

Conversation

@wmeddie

@wmeddie wmeddie commented Jun 26, 2026 •

Copy link
Copy Markdown
Member

Problem

encode_prompt() only builds the Bedrock Messages payload when the model id starts with anthropic.claude-3 or apac.anthropic.claude-3:

if model_id.startswith('anthropic.claude-3') or model_id.startswith('apac.anthropic.claude-3'):

Claude 4.5 inference-profile ids match neither — different region prefix (jp.) and version (4-5, not 3):

  • jp.anthropic.claude-sonnet-4-5-20250929-v1:0
  • jp.anthropic.claude-haiku-4-5-20251001-v1:0

So encode_prompt returns an empty messages list and every InvokeModel call fails with messages: at least one message is required. With the comma-separated fallback from this branch, both candidates fail and the agent dies:

[bedrock-agent] all models failed: [
 ('jp.anthropic.claude-sonnet-4-5-20250929-v1:0', "ValidationException(... at least one message is required)"),
 ('jp.anthropic.claude-haiku-4-5-20251001-v1:0', "ValidationException(... at least one message is required)")]

This breaks any downstream agent that adopts the 4.5 model ids.

Fix

Match any anthropic.claude model id instead, covering all region prefixes (jp./apac./us./eu./none) and versions. The Messages content-block format (and the system → user rewrite for mid-conversation messages) is identical across Claude 3+ models.

-    if model_id.startswith('anthropic.claude-3') or model_id.startswith('apac.anthropic.claude-3'):
+    if 'anthropic.claude' in model_id:

Verified encode_prompt now returns non-empty messages for both 4.5 ids and the legacy anthropic.claude-3-5 / apac.anthropic.claude-3-5 ids (regression-safe), while non-Claude ids (e.g. Titan) still return empty.

Based on bedrock-model-fallback (PR #10) since that branch introduced the model ids that expose this.

encode_prompt only built the Bedrock Messages payload when the model id
started with `anthropic.claude-3` / `apac.anthropic.claude-3`. The newer
Claude 4.5 inference-profile ids (e.g. `jp.anthropic.claude-sonnet-4-5`,
`jp.anthropic.claude-haiku-4-5`) fell through the guard, so the function
returned an empty messages list and every InvokeModel call failed with
"messages: at least one message is required".

Match any `anthropic.claude` model id instead, covering all region
prefixes (jp./apac./us./eu./none) and versions. The Messages
content-block format is identical across Claude 3+ models.
@wmeddie
wmeddie merged commit 3cdda83 into bedrock-model-fallback Jun 26, 2026
3 checks passed
@wmeddie
wmeddie deleted the fix/encode-prompt-claude4-models branch June 26, 2026 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant