Skip to content

Commit 4e9ed26

Browse files
authored
chore(log): added warning for default model awareness and is subject to change (strands-agents#2164)
1 parent 5a6df59 commit 4e9ed26

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

src/strands/models/bedrock.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,4 +1123,10 @@ def _get_default_model_with_warning(region_name: str, model_config: BedrockConfi
11231123
stacklevel=2,
11241124
)
11251125

1126-
return _DEFAULT_BEDROCK_MODEL_ID.format(prefix_inference_map.get(prefix, prefix))
1126+
default_model_id = _DEFAULT_BEDROCK_MODEL_ID.format(prefix_inference_map.get(prefix, prefix))
1127+
warnings.warn(
1128+
f"You're using default model '{default_model_id}', which is subject to change. "
1129+
"Specify a model explicitly to pin the model target.",
1130+
stacklevel=2,
1131+
)
1132+
return default_model_id

tests/strands/models/test_bedrock.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,25 +2169,25 @@ def test_get_default_model_with_warning_supported_regions_shows_no_warning(captu
21692169
"""Test get_model_prefix_with_warning doesn't warn for supported region prefixes."""
21702170
BedrockModel._get_default_model_with_warning("us-west-2")
21712171
BedrockModel._get_default_model_with_warning("eu-west-2")
2172-
assert len(captured_warnings) == 0
2172+
assert all("does not support" not in str(w.message) for w in captured_warnings)
21732173

21742174

21752175
def test_get_default_model_for_supported_eu_region_returns_correct_model_id(captured_warnings):
21762176
model_id = BedrockModel._get_default_model_with_warning("eu-west-1")
21772177
assert model_id == "eu.anthropic.claude-sonnet-4-20250514-v1:0"
2178-
assert len(captured_warnings) == 0
2178+
assert all("does not support" not in str(w.message) for w in captured_warnings)
21792179

21802180

21812181
def test_get_default_model_for_supported_us_region_returns_correct_model_id(captured_warnings):
21822182
model_id = BedrockModel._get_default_model_with_warning("us-east-1")
21832183
assert model_id == "us.anthropic.claude-sonnet-4-20250514-v1:0"
2184-
assert len(captured_warnings) == 0
2184+
assert all("does not support" not in str(w.message) for w in captured_warnings)
21852185

21862186

21872187
def test_get_default_model_for_supported_gov_region_returns_correct_model_id(captured_warnings):
21882188
model_id = BedrockModel._get_default_model_with_warning("us-gov-west-1")
21892189
assert model_id == "us-gov.anthropic.claude-sonnet-4-20250514-v1:0"
2190-
assert len(captured_warnings) == 0
2190+
assert all("does not support" not in str(w.message) for w in captured_warnings)
21912191

21922192

21932193
def test_get_model_prefix_for_ap_region_converts_to_apac_endpoint(captured_warnings):
@@ -2199,9 +2199,10 @@ def test_get_model_prefix_for_ap_region_converts_to_apac_endpoint(captured_warni
21992199
def test_get_default_model_with_warning_unsupported_region_warns(captured_warnings):
22002200
"""Test _get_default_model_with_warning warns for unsupported regions."""
22012201
BedrockModel._get_default_model_with_warning("ca-central-1")
2202-
assert len(captured_warnings) == 1
2203-
assert "This region ca-central-1 does not support" in str(captured_warnings[0].message)
2204-
assert "our default inference endpoint" in str(captured_warnings[0].message)
2202+
region_warnings = [w for w in captured_warnings if "does not support" in str(w.message)]
2203+
assert len(region_warnings) == 1
2204+
assert "This region ca-central-1 does not support" in str(region_warnings[0].message)
2205+
assert "our default inference endpoint" in str(region_warnings[0].message)
22052206

22062207

22072208
def test_get_default_model_with_warning_no_warning_with_custom_model_id(captured_warnings):
@@ -2217,8 +2218,9 @@ def test_init_with_unsupported_region_warns(session_cls, captured_warnings):
22172218
"""Test BedrockModel initialization warns for unsupported regions."""
22182219
BedrockModel(region_name="ca-central-1")
22192220

2220-
assert len(captured_warnings) == 1
2221-
assert "This region ca-central-1 does not support" in str(captured_warnings[0].message)
2221+
region_warnings = [w for w in captured_warnings if "does not support" in str(w.message)]
2222+
assert len(region_warnings) == 1
2223+
assert "This region ca-central-1 does not support" in str(region_warnings[0].message)
22222224

22232225

22242226
def test_init_with_unsupported_region_custom_model_no_warning(session_cls, captured_warnings):
@@ -2237,7 +2239,7 @@ def test_no_override_uses_formatted_default_model_id(captured_warnings):
22372239
model_id = BedrockModel._get_default_model_with_warning("us-east-1")
22382240
assert model_id == "us.anthropic.claude-sonnet-4-20250514-v1:0"
22392241
assert model_id != _DEFAULT_BEDROCK_MODEL_ID
2240-
assert len(captured_warnings) == 0
2242+
assert all("does not support" not in str(w.message) for w in captured_warnings)
22412243

22422244

22432245
def test_custom_model_id_not_overridden_by_region_formatting(session_cls):

0 commit comments

Comments
 (0)