Skip to content

fix(bedrock): preserve dots in Bedrock model IDs during normalization - #12778

Closed
chhanz wants to merge 1 commit into
NousResearch:mainfrom
chhanz:fix/bedrock-model-id-normalize
Closed

fix(bedrock): preserve dots in Bedrock model IDs during normalization#12778
chhanz wants to merge 1 commit into
NousResearch:mainfrom
chhanz:fix/bedrock-model-id-normalize

Conversation

@chhanz

@chhanz chhanz commented Apr 20, 2026

Copy link
Copy Markdown

What does this PR do?

normalize_model_name() unconditionally replaces all dots with hyphens, which breaks Bedrock model IDs where dots are structural separators (e.g.
global.anthropic.claude-opus-4-6-v1 becomes the invalid global-anthropic-claude-opus-4-6-v1). This causes all Claude models on Bedrock to fail with ValidationException: The provided model identifier is invalid, while Nova models (which use the bedrock_converse path) work fine.

This PR adds a _is_bedrock_model_id() helper to detect Bedrock-native IDs by their regional/vendor prefixes and skips dot-to-hyphen conversion for them.

Root Cause

normalize_model_name() was designed for OpenRouter-style names (claude-opus-4.6claude-opus-4-6) but did not account for Bedrock-native IDs where dots delimit
region/vendor/model hierarchy.

Related Issue

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • agent/anthropic_adapter.py: Added _is_bedrock_model_id() helper that detects Bedrock model ID patterns by regional prefixes (global., us., eu., ap., apac., jp.) and
    foundation model prefix (anthropic.claude)
  • agent/anthropic_adapter.py: Modified normalize_model_name() to return early (preserving dots) when _is_bedrock_model_id() returns True
  • tests/agent/test_anthropic_adapter.py: Added TestIsBedrockModelId class and test_preserves_dots_in_bedrock_model_ids test method (6 new test cases)

How to Test

  1. Configure Hermes with Bedrock provider (e.g. region ap-northeast-2)
  2. Set model to any Claude inference profile (e.g. global.anthropic.claude-opus-4-6-v1)
  3. Send any message

Before fix: ValidationException: The provided model identifier is invalid.
After fix: Normal response from Claude via AnthropicBedrock SDK

Affected Model ID Patterns

Pattern Example Dots are...
Global inference profile global.anthropic.claude-opus-4-6-v1 structural (preserved ✓)
Regional inference profile apac.anthropic.claude-sonnet-4-20250514-v1:0 structural (preserved ✓)
Foundation model anthropic.claude-opus-4-6-v1 structural (preserved ✓)
OpenRouter format claude-opus-4.6 version separator (converted → claude-opus-4-6 ✓)
Aggregator slug anthropic/claude-sonnet-4.6 version separator (converted → claude-sonnet-4-6 ✓)

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: Amazon Linux 2023 (EC2, ap-northeast-2, Python 3.11.14)

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility
    guide
    — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

Error log (before fix)

ERROR root: API call failed after 3 retries. An error occurred (ValidationException)
when calling the ConverseStream operation: The provided model identifier is invalid.
| provider=bedrock model=global.anthropic.claude-opus-4-7 msgs=2 tokens=~3,106

Test results (after fix)

$ venv/bin/python -m pytest tests/agent/test_anthropic_adapter.py -q
126 passed in 5.12s

Verification

>>> from agent.anthropic_adapter import normalize_model_name
>>> normalize_model_name("global.anthropic.claude-opus-4-6-v1")
'global.anthropic.claude-opus-4-6-v1'  # dots preserved ✓
>>> normalize_model_name("claude-opus-4.6")
'claude-opus-4-6'  # still converts OpenRouter format ✓
>>> normalize_model_name("anthropic/claude-sonnet-4.6")
'claude-sonnet-4-6'  # still strips prefix and converts ✓

normalize_model_name() unconditionally replaces all dots with hyphens,
which breaks Bedrock model IDs where dots are structural separators
(e.g. global.anthropic.claude-opus-4-6-v1 becomes the invalid
global-anthropic-claude-opus-4-6-v1). This causes all Claude models on
Bedrock to fail with "The provided model identifier is invalid" while
Nova models (which use the bedrock_converse path) work fine.

Add _is_bedrock_model_id() helper to detect Bedrock-native IDs by their
regional/vendor prefixes and skip dot-to-hyphen conversion for them.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/bedrock AWS Bedrock (boto3, IAM) labels Apr 23, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Multiple competing PRs for Bedrock dot preservation: #13821, #13112, #11700. This one uses prefix detection; #13821 uses URL heuristic.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the contribution @chhanz! This fix has been implemented on main independently.

This is an automated hermes-sweeper review.

The same bug was fixed by a parallel PR (#12295) which merged on 2026-04-23 as commit f2fba4f9a:

  • agent/anthropic_adapter.py now contains _is_bedrock_model_id() at line 989 covering the same prefixes (anthropic., us., eu., ap., jp., global.)
  • normalize_model_name() already guards against dot-to-hyphen conversion for Bedrock IDs at line 1027

Member @alt-glitch also flagged the competing PRs (#13821, #13112, #11700) in their review comment. Your analysis and test cases were solid — they just arrived slightly after another fix landed. Closing as implemented on main.

@teknium1 teknium1 closed this Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists provider/bedrock AWS Bedrock (boto3, IAM) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants