Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/aws/langchain_aws/chat_models/bedrock_converse.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class Joke(BaseModel):
}

model = ChatBedrockConverse(
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0",
max_tokens=5000,
region_name="us-west-2",
additional_model_request_fields=thinking_params,
Expand Down
2 changes: 1 addition & 1 deletion libs/aws/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ readme = "README.md"

[project.urls]
"Source Code" = "https://github.com/langchain-ai/langchain-aws/tree/main/libs/aws"
repository = "https://github.com/langchain-ai/langchain-aws"
Repository = "https://github.com/langchain-ai/langchain-aws"

[project.optional-dependencies]
tools = ["bedrock-agentcore>=0.1.0; python_version>='3.10'", "playwright>=1.53.0", "beautifulsoup4>=4.13.4"]
Expand Down
36 changes: 18 additions & 18 deletions libs/aws/tests/integration_tests/chat_models/test_bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@pytest.fixture
def chat() -> ChatBedrock:
return ChatBedrock(
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0",
model_kwargs={"temperature": 0},
) # type: ignore[call-arg]

Expand Down Expand Up @@ -84,7 +84,7 @@ def test_chat_bedrock_generate_with_token_usage(chat: ChatBedrock) -> None:
def test_chat_bedrock_streaming() -> None:
"""Test that streaming correctly streams chunks."""
chat = ChatBedrock( # type: ignore[call-arg]
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0"
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0"
)
message = HumanMessage(content="Hello")
stream = chat.stream([message])
Expand All @@ -101,7 +101,7 @@ def test_chat_bedrock_streaming() -> None:
@pytest.mark.scheduled
def test_chat_bedrock_token_counts() -> None:
chat = ChatBedrock( # type: ignore[call-arg]
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0",
model_kwargs={"temperature": 0},
)
invoke_response = chat.invoke("hi", max_tokens=6)
Expand All @@ -117,7 +117,7 @@ def test_chat_bedrock_token_counts() -> None:
assert stream_response.usage_metadata is not None
assert stream_response.usage_metadata["output_tokens"] <= 6
model_name = stream_response.response_metadata["model_name"]
assert model_name == "us.anthropic.claude-3-7-sonnet-20250219-v1:0"
assert model_name == "us.anthropic.claude-sonnet-4-5-20250929-v1:0"


@pytest.mark.scheduled
Expand Down Expand Up @@ -230,7 +230,7 @@ def on_llm_end(

callback = _FakeCallback()
chat = ChatBedrock( # type: ignore[call-arg]
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0",
callbacks=[callback],
model_kwargs={"temperature": 0},
)
Expand All @@ -244,7 +244,7 @@ def on_llm_end(
@pytest.mark.parametrize(
"model",
[
"us.anthropic.claude-3-7-sonnet-20250219-v1:0",
"us.anthropic.claude-sonnet-4-5-20250929-v1:0",
"mistral.mistral-7b-instruct-v0:2",
],
)
Expand All @@ -269,7 +269,7 @@ def test_bedrock_streaming(model: str) -> None:
@pytest.mark.parametrize(
"model",
[
"us.anthropic.claude-3-7-sonnet-20250219-v1:0",
"us.anthropic.claude-sonnet-4-5-20250929-v1:0",
"mistral.mistral-7b-instruct-v0:2",
],
)
Expand Down Expand Up @@ -337,7 +337,7 @@ def test_bedrock_invoke(chat: ChatBedrock) -> None:
def test_get_num_tokens_from_messages_integration() -> None:
"""Test get_num_tokens_from_messages with both message formats."""
chat = ChatBedrock(
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0",
)

base_messages = [
Expand Down Expand Up @@ -367,7 +367,7 @@ class AnswerWithJustification(BaseModel):
@pytest.mark.scheduled
def test_structured_output() -> None:
chat = ChatBedrock(
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0",
model_kwargs={"temperature": 0.001},
) # type: ignore[call-arg]
structured_llm = chat.with_structured_output(AnswerWithJustification)
Expand All @@ -381,7 +381,7 @@ def test_structured_output() -> None:

@pytest.mark.scheduled
def test_structured_output_anthropic_format() -> None:
chat = ChatBedrock(model="us.anthropic.claude-3-7-sonnet-20250219-v1:0") # type: ignore[call-arg]
chat = ChatBedrock(model="us.anthropic.claude-sonnet-4-5-20250929-v1:0") # type: ignore[call-arg]
schema = {
"name": "AnswerWithJustification",
"description": (
Expand Down Expand Up @@ -416,7 +416,7 @@ class Joke(TypedDict):
@pytest.mark.scheduled
def test_structured_output_streaming_dict() -> None:
chat = ChatBedrock(
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0",
temperature=0.0,
streaming=True,
)
Expand Down Expand Up @@ -445,7 +445,7 @@ class JokePyd(BaseModel):
@pytest.mark.scheduled
def test_structured_output_streaming_pydantic() -> None:
model = ChatBedrock(
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0",
temperature=0.0,
streaming=True,
)
Expand All @@ -464,7 +464,7 @@ def test_structured_output_streaming_pydantic() -> None:
@pytest.mark.scheduled
def test_tool_use_call_invoke() -> None:
chat = ChatBedrock(
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0",
model_kwargs={"temperature": 0.001},
) # type: ignore[call-arg]

Expand Down Expand Up @@ -501,7 +501,7 @@ def test_tool_use_call_invoke() -> None:
@pytest.mark.parametrize("tool_choice", ["GetWeather", "auto", "any"])
def test_anthropic_bind_tools_tool_choice(tool_choice: str) -> None:
chat = ChatBedrock(
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0",
model_kwargs={"temperature": 0.001},
) # type: ignore[call-arg]
chat_model_with_tools = chat.bind_tools([GetWeather], tool_choice=tool_choice)
Expand All @@ -519,7 +519,7 @@ def test_chat_bedrock_token_callbacks() -> None:
"""Test that streaming correctly invokes on_llm_end and stores token counts and stop reason.""" # noqa: E501
callback_handler = FakeCallbackHandlerWithTokenCounts()
chat = ChatBedrock( # type: ignore[call-arg]
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0",
streaming=False,
verbose=True,
)
Expand Down Expand Up @@ -746,7 +746,7 @@ def test_citations_bedrock(output_version: Literal["v0", "v1"]) -> None:
def test_guardrails() -> None:
params = {
"region_name": "us-west-2",
"model": "us.anthropic.claude-3-7-sonnet-20250219-v1:0",
"model": "us.anthropic.claude-sonnet-4-5-20250929-v1:0",
"guardrails": {
"guardrailIdentifier": "e7esbceow153",
"guardrailVersion": "1",
Expand Down Expand Up @@ -837,7 +837,7 @@ def test_guardrails_streaming_trace() -> None:

# Create ChatBedrock with guardrails (NOT using Converse API)
chat_model = ChatBedrock(
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0",
model_kwargs={"temperature": 0},
guardrails=guardrail_config,
callbacks=[guardrail_callback],
Expand All @@ -851,7 +851,7 @@ def test_guardrails_streaming_trace() -> None:
# Test 1: Verify invoke() captures guardrail traces
invoke_callback = GuardrailTraceCallbackHandler()
chat_model_invoke = ChatBedrock(
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0",
model_kwargs={"temperature": 0},
guardrails=guardrail_config,
callbacks=[invoke_callback],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def chat_model_class(self) -> Type[BaseChatModel]:

@property
def chat_model_params(self) -> dict:
return {"model": "us.anthropic.claude-3-7-sonnet-20250219-v1:0"}
return {"model": "us.anthropic.claude-sonnet-4-5-20250929-v1:0"}

@property
def standard_chat_model_params(self) -> dict:
Expand Down Expand Up @@ -195,7 +195,7 @@ def test_tool_message_histories_list_content(

def test_multiple_system_messages_anthropic() -> None:
model = ChatBedrockConverse(
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0", temperature=0
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0", temperature=0
)

system1 = SystemMessage(content="You are a helpful assistant.")
Expand All @@ -217,7 +217,7 @@ class ClassifyQuery(BaseModel):

def test_structured_output_snake_case() -> None:
model = ChatBedrockConverse(
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0", temperature=0
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0", temperature=0
)

chat = model.with_structured_output(ClassifyQuery)
Expand All @@ -226,7 +226,7 @@ def test_structured_output_snake_case() -> None:


def test_tool_calling_snake_case() -> None:
model = ChatBedrockConverse(model="us.anthropic.claude-3-7-sonnet-20250219-v1:0")
model = ChatBedrockConverse(model="us.anthropic.claude-sonnet-4-5-20250929-v1:0")

def classify_query(query_type: Literal["cat", "dog"]) -> None:
pass
Expand Down Expand Up @@ -258,7 +258,7 @@ def classify_query(query_type: Literal["cat", "dog"]) -> None:


def test_tool_calling_camel_case() -> None:
model = ChatBedrockConverse(model="us.anthropic.claude-3-7-sonnet-20250219-v1:0")
model = ChatBedrockConverse(model="us.anthropic.claude-sonnet-4-5-20250929-v1:0")

def classifyQuery(queryType: Literal["cat", "dog"]) -> None:
pass
Expand All @@ -284,7 +284,7 @@ def classifyQuery(queryType: Literal["cat", "dog"]) -> None:

def test_structured_output_streaming() -> None:
model = ChatBedrockConverse(
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0", temperature=0
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0", temperature=0
)
query = (
"What weighs more, a pound of bricks or a pound of feathers? "
Expand Down Expand Up @@ -354,7 +354,7 @@ class ToolClass(BaseModel):

# Create the model instance
model = ChatBedrockConverse(
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0", temperature=0
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0", temperature=0
)

# Create cache point configuration
Expand All @@ -381,7 +381,7 @@ class ToolClass(BaseModel):
def test_guardrails() -> None:
params = {
"region_name": "us-west-2",
"model": "us.anthropic.claude-3-7-sonnet-20250219-v1:0",
"model": "us.anthropic.claude-sonnet-4-5-20250929-v1:0",
"temperature": 0,
"max_tokens": 100,
"stop": [],
Expand Down Expand Up @@ -428,7 +428,7 @@ def test_guardrails() -> None:
@pytest.mark.parametrize(
"thinking_model",
[
"us.anthropic.claude-3-7-sonnet-20250219-v1:0",
"us.anthropic.claude-sonnet-4-5-20250929-v1:0",
"us.anthropic.claude-sonnet-4-20250514-v1:0",
"us.anthropic.claude-opus-4-20250514-v1:0",
"us.anthropic.claude-opus-4-1-20250805-v1:0",
Expand Down Expand Up @@ -470,15 +470,15 @@ def test_structured_output_thinking_force_tool_use() -> None:
# be removed.

# Instantiate as convenience for getting client
llm = ChatBedrockConverse(model="us.anthropic.claude-3-7-sonnet-20250219-v1:0")
llm = ChatBedrockConverse(model="us.anthropic.claude-sonnet-4-5-20250929-v1:0")
messages = [
{
"role": "user",
"content": [{"text": "Generate a username for Sally with green hair"}],
}
]
params = {
"modelId": "us.anthropic.claude-3-7-sonnet-20250219-v1:0",
"modelId": "us.anthropic.claude-sonnet-4-5-20250929-v1:0",
"inferenceConfig": {"maxTokens": 5000},
"toolConfig": {
"tools": [
Expand Down Expand Up @@ -762,7 +762,7 @@ def test_citations_v1(output_version: Literal["v0", "v1"]) -> None:

@pytest.mark.vcr
def test_pdf_citations() -> None:
model = ChatBedrockConverse(model="us.anthropic.claude-3-7-sonnet-20250219-v1:0")
model = ChatBedrockConverse(model="us.anthropic.claude-sonnet-4-5-20250929-v1:0")

message = HumanMessage(
[
Expand All @@ -775,7 +775,7 @@ def test_pdf_citations() -> None:


def test_bedrock_pdf_inputs() -> None:
model = ChatBedrockConverse(model="us.anthropic.claude-3-7-sonnet-20250219-v1:0")
model = ChatBedrockConverse(model="us.anthropic.claude-sonnet-4-5-20250929-v1:0")

message = HumanMessage(
[
Expand Down Expand Up @@ -806,7 +806,7 @@ def test_bedrock_pdf_inputs() -> None:

def test_get_num_tokens_from_messages_integration() -> None:
chat = ChatBedrockConverse(
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0",
)

base_messages = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def chat_model_class(self) -> Type[BaseChatModel]:
@property
def chat_model_params(self) -> dict:
return {
"model_id": "us.anthropic.claude-3-7-sonnet-20250219-v1:0",
"model_id": "us.anthropic.claude-sonnet-4-5-20250929-v1:0",
"beta_use_converse_api": True,
}

Expand Down
18 changes: 9 additions & 9 deletions libs/aws/tests/unit_tests/chat_models/test_bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ class GetWeather(BaseModel):

def test_anthropic_bind_tools_tool_choice() -> None:
chat_model = ChatBedrock(
model_id="anthropic.claude-3-opus-20240229", region_name="us-west-2"
model_id="anthropic.claude-opus-4-1-20250805-v1:0", region_name="us-west-2"
) # type: ignore[call-arg]
chat_model_with_tools = chat_model.bind_tools(
[GetWeather], tool_choice={"type": "tool", "name": "GetWeather"}
Expand Down Expand Up @@ -556,12 +556,12 @@ def test_anthropic_bind_tools_tool_choice() -> None:
],
)
@mock.patch("langchain_aws.chat_models.bedrock.create_aws_client")
def test_claude37_thinking_forced_tool_raises(
def test_claude_thinking_forced_tool_raises(
mock_create_aws_client, tool_choice
) -> None:
mock_create_aws_client.return_value = MagicMock()
chat = ChatBedrock(
model_id="anthropic.claude-3-7-sonnet-20250219-v1:0",
model_id="anthropic.claude-sonnet-4-5-20250929-v1:0",
region_name="us-west-2",
model_kwargs={
"thinking": {"type": "enabled", "budget_tokens": 2048},
Expand All @@ -572,10 +572,10 @@ def test_claude37_thinking_forced_tool_raises(


@mock.patch("langchain_aws.chat_models.bedrock.create_aws_client")
def test_claude37_thinking_tool_choice_auto_ok(mock_create_aws_client) -> None:
def test_claude_thinking_tool_choice_auto_ok(mock_create_aws_client) -> None:
mock_create_aws_client.return_value = MagicMock()
chat = ChatBedrock(
model_id="anthropic.claude-3-7-sonnet-20250219-v1:0",
model_id="anthropic.claude-sonnet-4-5-20250929-v1:0",
region_name="us-west-2",
model_kwargs={
"thinking": {"type": "enabled", "budget_tokens": 2048},
Expand All @@ -588,10 +588,10 @@ def test_claude37_thinking_tool_choice_auto_ok(mock_create_aws_client) -> None:


@mock.patch("langchain_aws.chat_models.bedrock.create_aws_client")
def test_claude37_no_thinking_forced_tool_ok(mock_create_aws_client) -> None:
def test_claude_no_thinking_forced_tool_ok(mock_create_aws_client) -> None:
mock_create_aws_client.return_value = MagicMock()
chat = ChatBedrock(
model_id="anthropic.claude-3-7-sonnet-20250219-v1:0",
model_id="anthropic.claude-sonnet-4-5-20250929-v1:0",
region_name="us-west-2",
)
chat_with_tools = chat.bind_tools([GetWeather], tool_choice="any")
Expand Down Expand Up @@ -1553,7 +1553,7 @@ def test_get_num_tokens_from_messages_with_base_messages():
mock_client.count_tokens.return_value = {"inputTokens": 20}

chat = ChatBedrock(
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0",
region="us-west-2",
max_tokens=4096,
)
Expand All @@ -1568,7 +1568,7 @@ def test_get_num_tokens_from_messages_with_base_messages():

mock_client.count_tokens.assert_called_once()
call_args = mock_client.count_tokens.call_args[1]
assert call_args["modelId"] == "anthropic.claude-3-7-sonnet-20250219-v1:0"
assert call_args["modelId"] == "anthropic.claude-sonnet-4-5-20250929-v1:0"

actual_input_body = json.loads(call_args["input"]["invokeModel"]["body"])
expected_input_body = {
Expand Down
Loading
Loading