Skip to content

The agent engineering platform.

fix(anthropic): clean up tests, update default model to use ID (#33751)

Mason Daugherty32d294b89a4d
diff --git a/libs/partners/anthropic/langchain_anthropic/chat_models.py b/libs/partners/anthropic/langchain_anthropic/chat_models.py
index a627646124..7ee7c8c1d8 100644
--- a/libs/partners/anthropic/langchain_anthropic/chat_models.py
+++ b/libs/partners/anthropic/langchain_anthropic/chat_models.py
@@ -60,13 +60,15 @@ _message_type_lookups = {
_MODEL_DEFAULT_MAX_OUTPUT_TOKENS: Final[dict[str, int]] = {
- "claude-opus-4-1": 32000,
- "claude-opus-4": 32000,
- "claude-sonnet-4": 64000,
- "claude-3-7-sonnet": 64000,
- "claude-3-5-sonnet": 8192,
- "claude-3-5-haiku": 8192,
- "claude-3-haiku": 4096,
+ # Listed old to new
+ "claude-3-haiku": 4096, # Claude Haiku 3
+ "claude-3-5-haiku": 8192, # Claude Haiku 3.5
+ "claude-3-7-sonnet": 64000, # Claude Sonnet 3.7
+ "claude-sonnet-4": 64000, # Claude Sonnet 4
+ "claude-opus-4": 32000, # Claude Opus 4
+ "claude-opus-4-1": 32000, # Claude Opus 4.1
+ "claude-sonnet-4-5": 64000, # Claude Sonnet 4.5
+ "claude-haiku-4-5": 64000, # Claude Haiku 4.5
}
_FALLBACK_MAX_OUTPUT_TOKENS: Final[int] = 4096
@@ -579,7 +581,7 @@ class ChatAnthropic(BaseChatModel):
Key init args — completion params:
model:
- Name of Anthropic model to use. e.g. `'claude-3-7-sonnet-20250219'`.
+ Name of Anthropic model to use. e.g. `'claude-sonnet-4-5-20250929'`.
temperature:
Sampling temperature. Ranges from `0.0` to `1.0`.
max_tokens:
@@ -607,7 +609,7 @@ class ChatAnthropic(BaseChatModel):
from langchain_anthropic import ChatAnthropic
model = ChatAnthropic(
- model="claude-3-7-sonnet-20250219",
+ model="claude-sonnet-4-5-20250929",
temperature=0,
max_tokens=1024,
timeout=None,
@@ -655,7 +657,7 @@ class ChatAnthropic(BaseChatModel):
content="J'aime la programmation.",
response_metadata={
"id": "msg_01Trik66aiQ9Z1higrD5XFx3",
- "model": "claude-3-7-sonnet-20250219",
+ "model": "claude-sonnet-4-5-20250929",
"stop_reason": "end_turn",
"stop_sequence": None,
"usage": {"input_tokens": 25, "output_tokens": 11},
@@ -714,7 +716,7 @@ class ChatAnthropic(BaseChatModel):
content="J'aime la programmation.",
response_metadata={
"id": "msg_01Trik66aiQ9Z1higrD5XFx3",
- "model": "claude-3-7-sonnet-20250219",
+ "model": "claude-sonnet-4-5-20250929",
"stop_reason": "end_turn",
"stop_sequence": None,
"usage": {"input_tokens": 25, "output_tokens": 11},
@@ -820,7 +822,7 @@ class ChatAnthropic(BaseChatModel):
image_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
image_data = base64.b64encode(httpx.get(image_url).content).decode("utf-8")
- model = ChatAnthropic(model="claude-sonnet-4-5")
+ model = ChatAnthropic(model="claude-sonnet-4-5-20250929")
message = HumanMessage(
content=[
{
@@ -855,7 +857,7 @@ class ChatAnthropic(BaseChatModel):
from langchain_anthropic import ChatAnthropic
model = ChatAnthropic(
- model="claude-sonnet-4-20250514",
+ model="claude-sonnet-4-5-20250929",
betas=["files-api-2025-04-14"],
)
input_message = {
@@ -887,7 +889,7 @@ class ChatAnthropic(BaseChatModel):
url = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
data = b64encode(requests.get(url).content).decode()
- model = ChatAnthropic(model="claude-sonnet-4-5")
+ model = ChatAnthropic(model="claude-sonnet-4-5-20250929")
ai_msg = model.invoke(
[
HumanMessage(
@@ -918,7 +920,7 @@ class ChatAnthropic(BaseChatModel):
from langchain_anthropic import ChatAnthropic
model = ChatAnthropic(
- model="claude-sonnet-4-20250514",
+ model="claude-sonnet-4-5-20250929",
betas=["files-api-2025-04-14"],
)
input_message = {
@@ -953,7 +955,7 @@ class ChatAnthropic(BaseChatModel):
from langchain_anthropic import ChatAnthropic
model = ChatAnthropic(
- model="claude-3-7-sonnet-latest",
+ model="claude-sonnet-4-5-20250929",
max_tokens=5000,
thinking={"type": "enabled", "budget_tokens": 2000},
)
@@ -988,7 +990,7 @@ class ChatAnthropic(BaseChatModel):
```python
from langchain_anthropic import ChatAnthropic
- model = ChatAnthropic(model="claude-3-5-haiku-latest")
+ model = ChatAnthropic(model="claude-3-5-haiku-20241022")
messages = [
{
@@ -1089,7 +1091,7 @@ class ChatAnthropic(BaseChatModel):
```python
from langchain_anthropic import ChatAnthropic
- model = ChatAnthropic(model="claude-3-7-sonnet-20250219")
+ model = ChatAnthropic(model="claude-sonnet-4-5-20250929")
messages = [
{
@@ -1139,7 +1141,7 @@ class ChatAnthropic(BaseChatModel):
```python
model = ChatAnthropic(
- model="claude-3-7-sonnet-20250219",
+ model="claude-sonnet-4-5-20250929",
)
messages = [
@@ -1192,7 +1194,7 @@ class ChatAnthropic(BaseChatModel):
from langchain_anthropic import ChatAnthropic
model = ChatAnthropic(
- model="claude-sonnet-4-20250514",
+ model="claude-sonnet-4-5-20250929",
betas=["context-1m-2025-08-07"], # Enable 1M context beta
)
@@ -1229,7 +1231,7 @@ class ChatAnthropic(BaseChatModel):
from langchain_core.tools import tool
model = ChatAnthropic(
- model="claude-3-7-sonnet-20250219",
+ model="claude-sonnet-4-5-20250929",
temperature=0,
model_kwargs={
"extra_headers": {
@@ -1268,7 +1270,7 @@ class ChatAnthropic(BaseChatModel):
from langchain_anthropic import ChatAnthropic
model = ChatAnthropic(
- model="claude-sonnet-4-5",
+ model="claude-sonnet-4-5-20250929",
betas=["context-management-2025-06-27"],
context_management={"edits": [{"type": "clear_tool_uses_20250919"}]},
)
@@ -1286,7 +1288,7 @@ class ChatAnthropic(BaseChatModel):
```python
from langchain_anthropic import ChatAnthropic
- model = ChatAnthropic(model="claude-3-5-haiku-latest")
+ model = ChatAnthropic(model="claude-3-5-haiku-20241022")
tool = {
"type": "web_search_20250305",
@@ -1304,7 +1306,7 @@ class ChatAnthropic(BaseChatModel):
from langchain_anthropic import ChatAnthropic
model = ChatAnthropic(
- model="claude-3-5-haiku-latest",
+ model="claude-3-5-haiku-20241022",
betas=["web-fetch-2025-09-10"], # Enable web fetch beta
)
@@ -1322,7 +1324,7 @@ class ChatAnthropic(BaseChatModel):
```python
model = ChatAnthropic(
- model="claude-sonnet-4-20250514",
+ model="claude-sonnet-4-5-20250929",
betas=["code-execution-2025-05-22"],
)
@@ -1353,7 +1355,7 @@ class ChatAnthropic(BaseChatModel):
]
model = ChatAnthropic(
- model="claude-sonnet-4-20250514",
+ model="claude-sonnet-4-5-20250929",
betas=["mcp-client-2025-04-04"],
mcp_servers=mcp_servers,
)
@@ -1369,7 +1371,7 @@ class ChatAnthropic(BaseChatModel):
```python
from langchain_anthropic import ChatAnthropic
- model = ChatAnthropic(model="claude-3-7-sonnet-20250219")
+ model = ChatAnthropic(model="claude-sonnet-4-5-20250929")
tool = {"type": "text_editor_20250124", "name": "str_replace_editor"}
model_with_tools = model.bind_tools([tool])
@@ -1396,7 +1398,7 @@ class ChatAnthropic(BaseChatModel):
from langchain_anthropic import ChatAnthropic
model = ChatAnthropic(
- model="claude-sonnet-4-5",
+ model="claude-sonnet-4-5-20250929",
betas=["context-management-2025-06-27"],
)
model_with_tools = model.bind_tools([{"type": "memory_20250818", "name": "memory"}])
@@ -1413,7 +1415,7 @@ class ChatAnthropic(BaseChatModel):
```python
{
"id": "msg_013xU6FHEGEq76aP4RgFerVT",
- "model": "claude-3-7-sonnet-20250219",
+ "model": "claude-sonnet-4-5-20250929",
"stop_reason": "end_turn",
"stop_sequence": None,
"usage": {"input_tokens": 25, "output_tokens": 11},
@@ -1948,7 +1950,7 @@ class ChatAnthropic(BaseChatModel):
product: str = Field(..., description="The product to look up.")
- model = ChatAnthropic(model="claude-sonnet-4-5", temperature=0)
+ model = ChatAnthropic(model="claude-sonnet-4-5-20250929", temperature=0)
model_with_tools = model.bind_tools([GetWeather, GetPrice])
model_with_tools.invoke(
"What is the weather like in San Francisco",
@@ -1958,7 +1960,7 @@ class ChatAnthropic(BaseChatModel):
# {'text': '<thinking>\nBased on the user\'s question, the relevant function to call is GetWeather, which requires the "location" parameter.\n\nThe user has directly specified the location as "San Francisco". Since San Francisco is a well known city, I can reasonably infer they mean San Francisco, CA without needing the state specified.\n\nAll the required parameters are provided, so I can proceed with the API call.\n</thinking>', 'type': 'text'},
# {'text': None, 'type': 'tool_use', 'id': 'toolu_01SCgExKzQ7eqSkMHfygvYuu', 'name': 'GetWeather', 'input': {'location': 'San Francisco, CA'}}
# ],
- # response_metadata={'id': 'msg_01GM3zQtoFv8jGQMW7abLnhi', 'model': 'claude-sonnet-4-5', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'input_tokens': 487, 'output_tokens': 145}},
+ # response_metadata={'id': 'msg_01GM3zQtoFv8jGQMW7abLnhi', 'model': 'claude-sonnet-4-5-20250929', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'input_tokens': 487, 'output_tokens': 145}},
# id='run-87b1331e-9251-4a68-acef-f0a018b639cc-0'
# )
```
@@ -1982,7 +1984,7 @@ class ChatAnthropic(BaseChatModel):
product: str = Field(..., description="The product to look up.")
- model = ChatAnthropic(model="claude-sonnet-4-5", temperature=0)
+ model = ChatAnthropic(model="claude-sonnet-4-5-20250929", temperature=0)
model_with_tools = model.bind_tools([GetWeather, GetPrice], tool_choice="any")
model_with_tools.invoke(
"what is the weather like in San Francisco",
@@ -2008,7 +2010,7 @@ class ChatAnthropic(BaseChatModel):
product: str = Field(..., description="The product to look up.")
- model = ChatAnthropic(model="claude-sonnet-4-5", temperature=0)
+ model = ChatAnthropic(model="claude-sonnet-4-5-20250929", temperature=0)
model_with_tools = model.bind_tools([GetWeather, GetPrice], tool_choice="GetWeather")
model_with_tools.invoke("What is the weather like in San Francisco")
```
@@ -2043,7 +2045,7 @@ class ChatAnthropic(BaseChatModel):
# We need to pass in extra headers to enable use of the beta cache
# control API.
model = ChatAnthropic(
- model="claude-sonnet-4-5",
+ model="claude-sonnet-4-5-20250929",
temperature=0,
)
model_with_tools = model.bind_tools([GetWeather, cached_price_tool])
@@ -2068,7 +2070,7 @@ class ChatAnthropic(BaseChatModel):
],
response_metadata={
"id": "msg_01Xg7Wr5inFWgBxE5jH9rpRo",
- "model": "claude-sonnet-4-5",
+ "model": "claude-sonnet-4-5-20250929",
"stop_reason": "tool_use",
"stop_sequence": None,
"usage": {
@@ -2113,7 +2115,7 @@ class ChatAnthropic(BaseChatModel):
],
response_metadata={
"id": "msg_016RfWHrRvW6DAGCdwB6Ac64",
- "model": "claude-sonnet-4-5",
+ "model": "claude-sonnet-4-5-20250929",
"stop_reason": "tool_use",
"stop_sequence": None,
"usage": {
@@ -2240,7 +2242,7 @@ class ChatAnthropic(BaseChatModel):
justification: str
- model = ChatAnthropic(model="claude-sonnet-4-5", temperature=0)
+ model = ChatAnthropic(model="claude-sonnet-4-5-20250929", temperature=0)
structured_model = model.with_structured_output(AnswerWithJustification)
structured_model.invoke("What weighs more a pound of bricks or a pound of feathers")
@@ -2265,7 +2267,7 @@ class ChatAnthropic(BaseChatModel):
justification: str
- model = ChatAnthropic(model="claude-sonnet-4-5", temperature=0)
+ model = ChatAnthropic(model="claude-sonnet-4-5-20250929", temperature=0)
structured_model = model.with_structured_output(AnswerWithJustification, include_raw=True)
structured_model.invoke("What weighs more a pound of bricks or a pound of feathers")
@@ -2293,7 +2295,7 @@ class ChatAnthropic(BaseChatModel):
"required": ["answer", "justification"],
},
}
- model = ChatAnthropic(model="claude-sonnet-4-5", temperature=0)
+ model = ChatAnthropic(model="claude-sonnet-4-5-20250929", temperature=0)
structured_model = model.with_structured_output(schema)
structured_model.invoke("What weighs more a pound of bricks or a pound of feathers")
diff --git a/libs/partners/anthropic/tests/cassettes/TestAnthropicStandard.test_stream_time.yaml.gz b/libs/partners/anthropic/tests/cassettes/TestAnthropicStandard.test_stream_time.yaml.gz
index 1b9b181b85..c1181a7138 100644
Binary files a/libs/partners/anthropic/tests/cassettes/TestAnthropicStandard.test_stream_time.yaml.gz and b/libs/partners/anthropic/tests/cassettes/TestAnthropicStandard.test_stream_time.yaml.gz differ
diff --git a/libs/partners/anthropic/tests/cassettes/test_agent_loop.yaml.gz b/libs/partners/anthropic/tests/cassettes/test_agent_loop.yaml.gz
index d53dffb02d..5bba3864cd 100644
Binary files a/libs/partners/anthropic/tests/cassettes/test_agent_loop.yaml.gz and b/libs/partners/anthropic/tests/cassettes/test_agent_loop.yaml.gz differ
diff --git a/libs/partners/anthropic/tests/cassettes/test_agent_loop_streaming.yaml.gz b/libs/partners/anthropic/tests/cassettes/test_agent_loop_streaming.yaml.gz
index 8e76e86628..7dc728333b 100644
Binary files a/libs/partners/anthropic/tests/cassettes/test_agent_loop_streaming.yaml.gz and b/libs/partners/anthropic/tests/cassettes/test_agent_loop_streaming.yaml.gz differ
diff --git a/libs/partners/anthropic/tests/cassettes/test_citations.yaml.gz b/libs/partners/anthropic/tests/cassettes/test_citations.yaml.gz
index c704ad451e..dd957413da 100644
Binary files a/libs/partners/anthropic/tests/cassettes/test_citations.yaml.gz and b/libs/partners/anthropic/tests/cassettes/test_citations.yaml.gz differ
diff --git a/libs/partners/anthropic/tests/cassettes/test_code_execution.yaml.gz b/libs/partners/anthropic/tests/cassettes/test_code_execution.yaml.gz
deleted file mode 100644
index f022211c38..0000000000
Binary files a/libs/partners/anthropic/tests/cassettes/test_code_execution.yaml.gz and /dev/null differ
diff --git a/libs/partners/anthropic/tests/cassettes/test_code_execution[v0].yaml.gz b/libs/partners/anthropic/tests/cassettes/test_code_execution[v0].yaml.gz
index b06c59fd78..f3e5eab068 100644
Binary files a/libs/partners/anthropic/tests/cassettes/test_code_execution[v0].yaml.gz and b/libs/partners/anthropic/tests/cassettes/test_code_execution[v0].yaml.gz differ
diff --git a/libs/partners/anthropic/tests/cassettes/test_code_execution[v1].yaml.gz b/libs/partners/anthropic/tests/cassettes/test_code_execution[v1].yaml.gz
index 3edf147f8c..56bf786f3d 100644
Binary files a/libs/partners/anthropic/tests/cassettes/test_code_execution[v1].yaml.gz and b/libs/partners/anthropic/tests/cassettes/test_code_execution[v1].yaml.gz differ
diff --git a/libs/partners/anthropic/tests/cassettes/test_context_management.yaml.gz b/libs/partners/anthropic/tests/cassettes/test_context_management.yaml.gz
index d8a866c91a..620cc31be4 100644
Binary files a/libs/partners/anthropic/tests/cassettes/test_context_management.yaml.gz and b/libs/partners/anthropic/tests/cassettes/test_context_management.yaml.gz differ
diff --git a/libs/partners/anthropic/tests/cassettes/test_redacted_thinking.yaml.gz b/libs/partners/anthropic/tests/cassettes/test_redacted_thinking.yaml.gz
index f4295b91e6..8a8ef49705 100644
Binary files a/libs/partners/anthropic/tests/cassettes/test_redacted_thinking.yaml.gz and b/libs/partners/anthropic/tests/cassettes/test_redacted_thinking.yaml.gz differ
diff --git a/libs/partners/anthropic/tests/cassettes/test_remote_mcp.yaml.gz b/libs/partners/anthropic/tests/cassettes/test_remote_mcp.yaml.gz
index c082b738dc..7bc6b91659 100644
Binary files a/libs/partners/anthropic/tests/cassettes/test_remote_mcp.yaml.gz and b/libs/partners/anthropic/tests/cassettes/test_remote_mcp.yaml.gz differ
diff --git a/libs/partners/anthropic/tests/cassettes/test_thinking.yaml.gz b/libs/partners/anthropic/tests/cassettes/test_thinking.yaml.gz
index 5c92ad877c..3da136f002 100644
Binary files a/libs/partners/anthropic/tests/cassettes/test_thinking.yaml.gz and b/libs/partners/anthropic/tests/cassettes/test_thinking.yaml.gz differ
diff --git a/libs/partners/anthropic/tests/cassettes/test_web_fetch.yaml.gz b/libs/partners/anthropic/tests/cassettes/test_web_fetch.yaml.gz
index 56db91c639..a9a0a51b9b 100644
Binary files a/libs/partners/anthropic/tests/cassettes/test_web_fetch.yaml.gz and b/libs/partners/anthropic/tests/cassettes/test_web_fetch.yaml.gz differ
diff --git a/libs/partners/anthropic/tests/cassettes/test_web_fetch_v1.yaml.gz b/libs/partners/anthropic/tests/cassettes/test_web_fetch_v1.yaml.gz
index 349d79944f..a2a4679c15 100644
Binary files a/libs/partners/anthropic/tests/cassettes/test_web_fetch_v1.yaml.gz and b/libs/partners/anthropic/tests/cassettes/test_web_fetch_v1.yaml.gz differ
diff --git a/libs/partners/anthropic/tests/cassettes/test_web_search.yaml.gz b/libs/partners/anthropic/tests/cassettes/test_web_search.yaml.gz
index 6802f28040..e8e4dea5bf 100644
Binary files a/libs/partners/anthropic/tests/cassettes/test_web_search.yaml.gz and b/libs/partners/anthropic/tests/cassettes/test_web_search.yaml.gz differ
diff --git a/libs/partners/anthropic/tests/integration_tests/test_chat_models.py b/libs/partners/anthropic/tests/integration_tests/test_chat_models.py
index cb1fbafc31..7041563c34 100644
--- a/libs/partners/anthropic/tests/integration_tests/test_chat_models.py
+++ b/libs/partners/anthropic/tests/integration_tests/test_chat_models.py
@@ -32,8 +32,7 @@ from langchain_anthropic import ChatAnthropic
from langchain_anthropic._compat import _convert_from_v1_to_anthropic
from tests.unit_tests._utils import FakeCallbackHandler
-MODEL_NAME = "claude-3-5-haiku-latest"
-IMAGE_MODEL_NAME = "claude-3-5-haiku-latest"
+MODEL_NAME = "claude-3-5-haiku-20241022"
def test_stream() -> None:
@@ -162,7 +161,7 @@ async def test_stream_usage_override() -> None:
async def test_abatch() -> None:
- """Test streaming tokens from ChatAnthropic."""
+ """Test streaming tokens."""
llm = ChatAnthropic(model_name=MODEL_NAME) # type: ignore[call-arg, call-arg]
result = await llm.abatch(["I'm Pickle Rick", "I'm not Pickle Rick"])
@@ -171,7 +170,7 @@ async def test_abatch() -> None:
async def test_abatch_tags() -> None:
- """Test batch tokens from ChatAnthropic."""
+ """Test batch tokens."""
llm = ChatAnthropic(model_name=MODEL_NAME) # type: ignore[call-arg, call-arg]
result = await llm.abatch(
@@ -232,7 +231,7 @@ async def test_async_tool_use() -> None:
def test_batch() -> None:
- """Test batch tokens from ChatAnthropic."""
+ """Test batch tokens."""
llm = ChatAnthropic(model_name=MODEL_NAME) # type: ignore[call-arg, call-arg]
result = llm.batch(["I'm Pickle Rick", "I'm not Pickle Rick"])
@@ -241,7 +240,7 @@ def test_batch() -> None:
async def test_ainvoke() -> None:
- """Test invoke tokens from ChatAnthropic."""
+ """Test invoke tokens."""
llm = ChatAnthropic(model_name=MODEL_NAME) # type: ignore[call-arg, call-arg]
result = await llm.ainvoke("I'm Pickle Rick", config={"tags": ["foo"]})
@@ -250,7 +249,7 @@ async def test_ainvoke() -> None:
def test_invoke() -> None:
- """Test invoke tokens from ChatAnthropic."""
+ """Test invoke tokens."""
llm = ChatAnthropic(model_name=MODEL_NAME) # type: ignore[call-arg, call-arg]
result = llm.invoke("I'm Pickle Rick", config={"tags": ["foo"]})
@@ -396,7 +395,7 @@ async def test_anthropic_async_streaming_callback() -> None:
def test_anthropic_multimodal() -> None:
"""Test that multimodal inputs are handled correctly."""
- chat = ChatAnthropic(model=IMAGE_MODEL_NAME) # type: ignore[call-arg]
+ chat = ChatAnthropic(model=MODEL_NAME) # type: ignore[call-arg]
messages: list[BaseMessage] = [
HumanMessage(
content=[
@@ -562,9 +561,9 @@ def test_tool_use() -> None:
assert len(chunks) > 1
-def test_builtin_tools() -> None:
- llm = ChatAnthropic(model="claude-3-7-sonnet-20250219") # type: ignore[call-arg]
- tool = {"type": "text_editor_20250124", "name": "str_replace_editor"}
+def test_builtin_tools_text_editor() -> None:
+ llm = ChatAnthropic(model="claude-sonnet-4-5-20250929") # type: ignore[call-arg]
+ tool = {"type": "text_editor_20250728", "name": "str_replace_based_edit_tool"}
llm_with_tools = llm.bind_tools([tool])
response = llm_with_tools.invoke(
"There's a syntax error in my primes.py file. Can you help me fix it?",
@@ -577,7 +576,7 @@ def test_builtin_tools() -> None:
assert content_blocks[0]["type"] == "text"
assert content_blocks[0]["text"]
assert content_blocks[1]["type"] == "tool_call"
- assert content_blocks[1]["name"] == "str_replace_editor"
+ assert content_blocks[1]["name"] == "str_replace_based_edit_tool"
class GenerateUsername(BaseModel):
@@ -588,7 +587,7 @@ class GenerateUsername(BaseModel):
def test_disable_parallel_tool_calling() -> None:
- llm = ChatAnthropic(model="claude-sonnet-4-5-20250929") # type: ignore[call-arg]
+ llm = ChatAnthropic(model=MODEL_NAME) # type: ignore[call-arg]
llm_with_tools = llm.bind_tools([GenerateUsername], parallel_tool_calls=False)
result = llm_with_tools.invoke(
"Use the GenerateUsername tool to generate user names for:\n\n"
@@ -607,7 +606,7 @@ def test_anthropic_with_empty_text_block() -> None:
"""Type the given letter."""
return "OK"
- model = ChatAnthropic(model="claude-3-opus-20240229", temperature=0).bind_tools( # type: ignore[call-arg]
+ model = ChatAnthropic(model=MODEL_NAME, temperature=0).bind_tools( # type: ignore[call-arg]
[type_letter],
)
@@ -646,7 +645,7 @@ def test_anthropic_with_empty_text_block() -> None:
def test_with_structured_output() -> None:
llm = ChatAnthropic(
- model="claude-3-opus-20240229", # type: ignore[call-arg]
+ model=MODEL_NAME, # type: ignore[call-arg]
)
structured_llm = llm.with_structured_output(
@@ -665,7 +664,7 @@ def test_with_structured_output() -> None:
def test_get_num_tokens_from_messages() -> None:
- llm = ChatAnthropic(model="claude-sonnet-4-5-20250929") # type: ignore[call-arg]
+ llm = ChatAnthropic(model=MODEL_NAME) # type: ignore[call-arg]
# Test simple case
messages = [
@@ -739,7 +738,7 @@ def test_pdf_document_input() -> None:
url = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
data = b64encode(requests.get(url, timeout=10).content).decode()
- result = ChatAnthropic(model=IMAGE_MODEL_NAME).invoke( # type: ignore[call-arg]
+ result = ChatAnthropic(model=MODEL_NAME).invoke( # type: ignore[call-arg]
[
HumanMessage(
[
@@ -770,7 +769,7 @@ def test_agent_loop(output_version: Literal["v0", "v1"]) -> None:
"""Get the weather for a location."""
return "It's sunny."
- llm = ChatAnthropic(model="claude-3-5-haiku-latest", output_version=output_version) # type: ignore[call-arg]
+ llm = ChatAnthropic(model=MODEL_NAME, output_version=output_version) # type: ignore[call-arg]
llm_with_tools = llm.bind_tools([get_weather])
input_message = HumanMessage("What is the weather in San Francisco, CA?")
tool_call_message = llm_with_tools.invoke([input_message])
@@ -800,7 +799,7 @@ def test_agent_loop_streaming(output_version: Literal["v0", "v1"]) -> None:
return "It's sunny."
llm = ChatAnthropic(
- model="claude-3-5-haiku-latest",
+ model=MODEL_NAME,
streaming=True,
output_version=output_version, # type: ignore[call-arg]
)
@@ -828,7 +827,7 @@ def test_agent_loop_streaming(output_version: Literal["v0", "v1"]) -> None:
@pytest.mark.vcr
@pytest.mark.parametrize("output_version", ["v0", "v1"])
def test_citations(output_version: Literal["v0", "v1"]) -> None:
- llm = ChatAnthropic(model="claude-3-5-haiku-latest", output_version=output_version) # type: ignore[call-arg]
+ llm = ChatAnthropic(model=MODEL_NAME, output_version=output_version) # type: ignore[call-arg]
messages = [
{
"role": "user",
@@ -879,7 +878,7 @@ def test_citations(output_version: Literal["v0", "v1"]) -> None:
@pytest.mark.vcr
def test_thinking() -> None:
llm = ChatAnthropic(
- model="claude-3-7-sonnet-latest", # type: ignore[call-arg]
+ model="claude-sonnet-4-5-20250929", # type: ignore[call-arg]
max_tokens=5_000, # type: ignore[call-arg]
thinking={"type": "enabled", "budget_tokens": 2_000},
)
@@ -921,7 +920,7 @@ def test_thinking() -> None:
@pytest.mark.vcr
def test_thinking_v1() -> None:
llm = ChatAnthropic(
- model="claude-3-7-sonnet-latest", # type: ignore[call-arg]
+ model="claude-sonnet-4-5-20250929", # type: ignore[call-arg]
max_tokens=5_000, # type: ignore[call-arg]
thinking={"type": "enabled", "budget_tokens": 2_000},
output_version="v1",
@@ -967,6 +966,8 @@ def test_thinking_v1() -> None:
@pytest.mark.parametrize("output_version", ["v0", "v1"])
def test_redacted_thinking(output_version: Literal["v0", "v1"]) -> None:
llm = ChatAnthropic(
+ # It appears that Sonnet 4.5 either: isn't returning redacted thinking blocks,
+ # or the magic string is broken? Retry later once 3-7 finally removed
model="claude-3-7-sonnet-latest", # type: ignore[call-arg]
max_tokens=5_000, # type: ignore[call-arg]
thinking={"type": "enabled", "budget_tokens": 2_000},
@@ -1029,7 +1030,7 @@ def test_redacted_thinking(output_version: Literal["v0", "v1"]) -> None:
def test_structured_output_thinking_enabled() -> None:
llm = ChatAnthropic(
- model="claude-3-7-sonnet-latest", # type: ignore[call-arg]
+ model="claude-sonnet-4-5-20250929", # type: ignore[call-arg]
max_tokens=5_000, # type: ignore[call-arg]
thinking={"type": "enabled", "budget_tokens": 2_000},
)
@@ -1052,7 +1053,7 @@ def test_structured_output_thinking_force_tool_use() -> None:
# when `thinking` is enabled. When this test fails, it means that the feature
# is supported and the workarounds in `with_structured_output` should be removed.
llm = ChatAnthropic(
- model="claude-3-7-sonnet-latest", # type: ignore[call-arg]
+ model="claude-sonnet-4-5-20250929", # type: ignore[call-arg]
max_tokens=5_000, # type: ignore[call-arg]
thinking={"type": "enabled", "budget_tokens": 2_000},
).bind_tools(
@@ -1120,7 +1121,7 @@ def test_image_tool_calling() -> None:
],
),
]
- llm = ChatAnthropic(model="claude-3-5-haiku-latest") # type: ignore[call-arg]
+ llm = ChatAnthropic(model=MODEL_NAME) # type: ignore[call-arg]
llm.bind_tools([color_picker]).invoke(messages)
@@ -1129,7 +1130,7 @@ def test_image_tool_calling() -> None:
@pytest.mark.parametrize("output_version", ["v0", "v1"])
def test_web_search(output_version: Literal["v0", "v1"]) -> None:
llm = ChatAnthropic(
- model="claude-3-5-haiku-latest", # type: ignore[call-arg]
+ model=MODEL_NAME, # type: ignore[call-arg]
max_tokens=1024,
output_version=output_version,
)
@@ -1178,68 +1179,6 @@ def test_web_search(output_version: Literal["v0", "v1"]) -> None:
)
[email protected]_cassette("test_web_fetch_v1.yaml.gz")
[email protected]("output_version", ["v0", "v1"])
-def test_web_fetch_v1(output_version: Literal["v0", "v1"]) -> None:
- """Test that http calls are unchanged between v0 and v1."""
- llm = ChatAnthropic(
- model="claude-3-5-haiku-latest", # type: ignore[call-arg]
- betas=["web-fetch-2025-09-10"],
- output_version=output_version,
- )
-
- if output_version == "v0":
- call_key = "server_tool_use"
- result_key = "web_fetch_tool_result"
- else:
- # v1
- call_key = "server_tool_call"
- result_key = "server_tool_result"
-
- tool = {
- "type": "web_fetch_20250910",
- "name": "web_fetch",
- "max_uses": 1,
- "citations": {"enabled": True},
- }
- llm_with_tools = llm.bind_tools([tool])
-
- input_message = {
- "role": "user",
- "content": [
- {
- "type": "text",
- "text": "Fetch the content at https://docs.langchain.com and analyze",
- },
- ],
- }
- response = llm_with_tools.invoke([input_message])
- assert all(isinstance(block, dict) for block in response.content)
- block_types = {block["type"] for block in response.content} # type: ignore[index]
- assert block_types == {"text", call_key, result_key}
-
- # Test streaming
- full: BaseMessageChunk | None = None
- for chunk in llm_with_tools.stream([input_message]):
- assert isinstance(chunk, AIMessageChunk)
- full = chunk if full is None else full + chunk
-
- assert isinstance(full, AIMessageChunk)
- assert isinstance(full.content, list)
- block_types = {block["type"] for block in full.content} # type: ignore[index]
- assert block_types == {"text", call_key, result_key}
-
- # Test we can pass back in
- next_message = {
- "role": "user",
- "content": "What does the site you just fetched say about models?",
- }
- _ = llm_with_tools.invoke(
- [input_message, full, next_message],
- )
-
-
@pytest.mark.vcr
def test_web_fetch() -> None:
"""Note: this is a beta feature.
@@ -1247,7 +1186,7 @@ def test_web_fetch() -> None:
TODO: Update to remove beta once it's generally available.
"""
llm = ChatAnthropic(
- model="claude-3-5-haiku-latest", # type: ignore[call-arg]
+ model=MODEL_NAME, # type: ignore[call-arg]
max_tokens=1024,
betas=["web-fetch-2025-09-10"],
)
@@ -1502,6 +1441,68 @@ def test_web_fetch() -> None:
assert "data" in content["content"]["source"]
[email protected]_cassette("test_web_fetch_v1.yaml.gz")
[email protected]("output_version", ["v0", "v1"])
+def test_web_fetch_v1(output_version: Literal["v0", "v1"]) -> None:
+ """Test that http calls are unchanged between v0 and v1."""
+ llm = ChatAnthropic(
+ model=MODEL_NAME, # type: ignore[call-arg]
+ betas=["web-fetch-2025-09-10"],
+ output_version=output_version,
+ )
+
+ if output_version == "v0":
+ call_key = "server_tool_use"
+ result_key = "web_fetch_tool_result"
+ else:
+ # v1
+ call_key = "server_tool_call"
+ result_key = "server_tool_result"
+
+ tool = {
+ "type": "web_fetch_20250910",
+ "name": "web_fetch",
+ "max_uses": 1,
+ "citations": {"enabled": True},
+ }
+ llm_with_tools = llm.bind_tools([tool])
+
+ input_message = {
+ "role": "user",
+ "content": [
+ {
+ "type": "text",
+ "text": "Fetch the content at https://docs.langchain.com and analyze",
+ },
+ ],
+ }
+ response = llm_with_tools.invoke([input_message])
+ assert all(isinstance(block, dict) for block in response.content)
+ block_types = {block["type"] for block in response.content} # type: ignore[index]
+ assert block_types == {"text", call_key, result_key}
+
+ # Test streaming
+ full: BaseMessageChunk | None = None
+ for chunk in llm_with_tools.stream([input_message]):
+ assert isinstance(chunk, AIMessageChunk)
+ full = chunk if full is None else full + chunk
+
+ assert isinstance(full, AIMessageChunk)
+ assert isinstance(full.content, list)
+ block_types = {block["type"] for block in full.content} # type: ignore[index]
+ assert block_types == {"text", call_key, result_key}
+
+ # Test we can pass back in
+ next_message = {
+ "role": "user",
+ "content": "What does the site you just fetched say about models?",
+ }
+ _ = llm_with_tools.invoke(
+ [input_message, full, next_message],
+ )
+
+
@pytest.mark.vcr
@pytest.mark.parametrize("output_version", ["v0", "v1"])
def test_code_execution(output_version: Literal["v0", "v1"]) -> None:
@@ -1510,9 +1511,8 @@ def test_code_execution(output_version: Literal["v0", "v1"]) -> None:
TODO: Update to remove beta once generally available.
"""
llm = ChatAnthropic(
- model="claude-sonnet-4-20250514", # type: ignore[call-arg]
+ model=MODEL_NAME, # type: ignore[call-arg]
betas=["code-execution-2025-05-22"],
- max_tokens=10_000, # type: ignore[call-arg]
output_version=output_version,
)
@@ -1581,7 +1581,7 @@ def test_remote_mcp(output_version: Literal["v0", "v1"]) -> None:
]
llm = ChatAnthropic(
- model="claude-sonnet-4-20250514", # type: ignore[call-arg]
+ model="claude-sonnet-4-5-20250929", # type: ignore[call-arg]
betas=["mcp-client-2025-04-04"],
mcp_servers=mcp_servers,
max_tokens=10_000, # type: ignore[call-arg]
@@ -1642,7 +1642,7 @@ def test_files_api_image(block_format: str) -> None:
if not image_file_id:
pytest.skip()
llm = ChatAnthropic(
- model="claude-sonnet-4-20250514", # type: ignore[call-arg]
+ model=MODEL_NAME, # type: ignore[call-arg]
betas=["files-api-2025-04-14"],
)
if block_format == "anthropic":
@@ -1679,7 +1679,7 @@ def test_files_api_pdf(block_format: str) -> None:
if not pdf_file_id:
pytest.skip()
llm = ChatAnthropic(
- model="claude-sonnet-4-20250514", # type: ignore[call-arg]
+ model=MODEL_NAME, # type: ignore[call-arg]
betas=["files-api-2025-04-14"],
)
if block_format == "anthropic":
@@ -1703,7 +1703,7 @@ def test_files_api_pdf(block_format: str) -> None:
def test_search_result_tool_message() -> None:
"""Test that we can pass a search result tool message to the model."""
llm = ChatAnthropic(
- model="claude-3-5-haiku-latest", # type: ignore[call-arg]
+ model=MODEL_NAME, # type: ignore[call-arg]
)
@tool
@@ -1760,7 +1760,7 @@ def test_search_result_tool_message() -> None:
def test_search_result_top_level() -> None:
llm = ChatAnthropic(
- model="claude-3-5-haiku-latest", # type: ignore[call-arg]
+ model=MODEL_NAME, # type: ignore[call-arg]
)
input_message = HumanMessage(
[
@@ -1810,7 +1810,7 @@ def test_search_result_top_level() -> None:
def test_memory_tool() -> None:
llm = ChatAnthropic(
- model="claude-sonnet-4-5", # type: ignore[call-arg]
+ model="claude-sonnet-4-5-20250929", # type: ignore[call-arg]
betas=["context-management-2025-06-27"],
)
llm_with_tools = llm.bind_tools([{"type": "memory_20250818", "name": "memory"}])
@@ -1824,7 +1824,7 @@ def test_memory_tool() -> None:
def test_context_management() -> None:
# TODO: update example to trigger action
llm = ChatAnthropic(
- model="claude-sonnet-4-5", # type: ignore[call-arg]
+ model="claude-sonnet-4-5-20250929", # type: ignore[call-arg]
betas=["context-management-2025-06-27"],
context_management={
"edits": [
@@ -1854,6 +1854,6 @@ def test_context_management() -> None:
def test_async_shared_client() -> None:
- llm = ChatAnthropic(model="claude-3-5-haiku-latest") # type: ignore[call-arg]
+ llm = ChatAnthropic(model=MODEL_NAME) # type: ignore[call-arg]
_ = asyncio.run(llm.ainvoke("Hello"))
_ = asyncio.run(llm.ainvoke("Hello"))
diff --git a/libs/partners/anthropic/tests/integration_tests/test_llms.py b/libs/partners/anthropic/tests/integration_tests/test_llms.py
index 1e8a433235..2bb8279744 100644
--- a/libs/partners/anthropic/tests/integration_tests/test_llms.py
+++ b/libs/partners/anthropic/tests/integration_tests/test_llms.py
@@ -9,7 +9,7 @@ from langchain_core.outputs import LLMResult
from langchain_anthropic import AnthropicLLM
from tests.unit_tests._utils import FakeCallbackHandler
-MODEL = "claude-3-7-sonnet-latest"
+MODEL = "claude-sonnet-4-5-20250929"
@pytest.mark.requires("anthropic")
diff --git a/libs/partners/anthropic/tests/integration_tests/test_standard.py b/libs/partners/anthropic/tests/integration_tests/test_standard.py
index 59dec97bf8..91b2a86ac0 100644
--- a/libs/partners/anthropic/tests/integration_tests/test_standard.py
+++ b/libs/partners/anthropic/tests/integration_tests/test_standard.py
@@ -11,7 +11,7 @@ from langchain_anthropic import ChatAnthropic
REPO_ROOT_DIR = Path(__file__).parents[5]
-MODEL = "claude-3-5-haiku-latest"
+MODEL = "claude-3-5-haiku-20241022"
class TestAnthropicStandard(ChatModelIntegrationTests):
diff --git a/libs/partners/anthropic/tests/unit_tests/test_chat_models.py b/libs/partners/anthropic/tests/unit_tests/test_chat_models.py
index b030b743c4..88f1ab5644 100644
--- a/libs/partners/anthropic/tests/unit_tests/test_chat_models.py
+++ b/libs/partners/anthropic/tests/unit_tests/test_chat_models.py
@@ -29,19 +29,21 @@ from langchain_anthropic.chat_models import (
os.environ["ANTHROPIC_API_KEY"] = "foo"
+MODEL_NAME = "claude-sonnet-4-5-20250929"
+
def test_initialization() -> None:
"""Test chat model initialization."""
for model in [
- ChatAnthropic(model_name="claude-instant-1.2", api_key="xyz", timeout=2), # type: ignore[arg-type, call-arg]
+ ChatAnthropic(model_name=MODEL_NAME, api_key="xyz", timeout=2), # type: ignore[arg-type, call-arg]
ChatAnthropic( # type: ignore[call-arg, call-arg, call-arg]
- model="claude-instant-1.2",
+ model=MODEL_NAME,
anthropic_api_key="xyz",
default_request_timeout=2,
base_url="https://api.anthropic.com",
),
]:
- assert model.model == "claude-instant-1.2"
+ assert model.model == MODEL_NAME
assert cast("SecretStr", model.anthropic_api_key).get_secret_value() == "xyz"
assert model.default_request_timeout == 2.0
assert model.anthropic_api_url == "https://api.anthropic.com"
@@ -49,23 +51,23 @@ def test_initialization() -> None:
@pytest.mark.parametrize("async_api", [True, False])
def test_streaming_attribute_should_stream(async_api: bool) -> None: # noqa: FBT001
- llm = ChatAnthropic(model="foo", streaming=True)
+ llm = ChatAnthropic(model=MODEL_NAME, streaming=True)
assert llm._should_stream(async_api=async_api)
def test_anthropic_client_caching() -> None:
"""Test that the OpenAI client is cached."""
- llm1 = ChatAnthropic(model="claude-sonnet-4-5")
- llm2 = ChatAnthropic(model="claude-sonnet-4-5")
+ llm1 = ChatAnthropic(model=MODEL_NAME)
+ llm2 = ChatAnthropic(model=MODEL_NAME)
assert llm1._client._client is llm2._client._client
- llm3 = ChatAnthropic(model="claude-sonnet-4-5", base_url="foo")
+ llm3 = ChatAnthropic(model=MODEL_NAME, base_url="foo")
assert llm1._client._client is not llm3._client._client
- llm4 = ChatAnthropic(model="claude-sonnet-4-5", timeout=None)
+ llm4 = ChatAnthropic(model=MODEL_NAME, timeout=None)
assert llm1._client._client is llm4._client._client
- llm5 = ChatAnthropic(model="claude-sonnet-4-5", timeout=3)
+ llm5 = ChatAnthropic(model=MODEL_NAME, timeout=3)
assert llm1._client._client is not llm5._client._client
@@ -74,7 +76,7 @@ def test_anthropic_proxy_support() -> None:
proxy_url = "http://proxy.example.com:8080"
# Test sync client with proxy
- llm_sync = ChatAnthropic(model="claude-sonnet-4-5", anthropic_proxy=proxy_url)
+ llm_sync = ChatAnthropic(model=MODEL_NAME, anthropic_proxy=proxy_url)
sync_client = llm_sync._client
assert sync_client is not None
@@ -83,8 +85,8 @@ def test_anthropic_proxy_support() -> None:
assert async_client is not None
# Test that clients with different proxy settings are not cached together
- llm_no_proxy = ChatAnthropic(model="claude-sonnet-4-5")
- llm_with_proxy = ChatAnthropic(model="claude-sonnet-4-5", anthropic_proxy=proxy_url)
+ llm_no_proxy = ChatAnthropic(model=MODEL_NAME)
+ llm_with_proxy = ChatAnthropic(model=MODEL_NAME, anthropic_proxy=proxy_url)
# Different proxy settings should result in different cached clients
assert llm_no_proxy._client._client is not llm_with_proxy._client._client
@@ -96,7 +98,7 @@ def test_anthropic_proxy_from_environment() -> None:
# Test with environment variable set
with patch.dict(os.environ, {"ANTHROPIC_PROXY": proxy_url}):
- llm = ChatAnthropic(model="claude-sonnet-4-5")
+ llm = ChatAnthropic(model=MODEL_NAME)
assert llm.anthropic_proxy == proxy_url
# Should be able to create clients successfully
@@ -108,76 +110,76 @@ def test_anthropic_proxy_from_environment() -> None:
# Test that explicit parameter overrides environment variable
with patch.dict(os.environ, {"ANTHROPIC_PROXY": "http://env-proxy.com"}):
explicit_proxy = "http://explicit-proxy.com"
- llm = ChatAnthropic(model="claude-sonnet-4-5", anthropic_proxy=explicit_proxy)
+ llm = ChatAnthropic(model=MODEL_NAME, anthropic_proxy=explicit_proxy)
assert llm.anthropic_proxy == explicit_proxy
def test_set_default_max_tokens() -> None:
"""Test the set_default_max_tokens function."""
+ # Test claude-sonnet-4-5 models
+ llm = ChatAnthropic(model="claude-sonnet-4-5-20250929", anthropic_api_key="test")
+ assert llm.max_tokens == 64000
+
# Test claude-opus-4 models
llm = ChatAnthropic(model="claude-opus-4-20250514", anthropic_api_key="test")
assert llm.max_tokens == 32000
# Test claude-sonnet-4 models
- llm = ChatAnthropic(model="claude-sonnet-4-latest", anthropic_api_key="test")
+ llm = ChatAnthropic(model="claude-sonnet-4-20250514", anthropic_api_key="test")
assert llm.max_tokens == 64000
# Test claude-3-7-sonnet models
- llm = ChatAnthropic(model="claude-3-7-sonnet-latest", anthropic_api_key="test")
+ llm = ChatAnthropic(model="claude-3-7-sonnet-20250219", anthropic_api_key="test")
assert llm.max_tokens == 64000
# Test claude-3-5-haiku models
- llm = ChatAnthropic(model="claude-3-5-haiku-latest", anthropic_api_key="test")
+ llm = ChatAnthropic(model="claude-3-5-haiku-20241022", anthropic_api_key="test")
assert llm.max_tokens == 8192
# Test claude-3-haiku models (should default to 4096)
- llm = ChatAnthropic(model="claude-3-haiku-latest", anthropic_api_key="test")
+ llm = ChatAnthropic(model="claude-3-haiku-20240307", anthropic_api_key="test")
assert llm.max_tokens == 4096
# Test that existing max_tokens values are preserved
- llm = ChatAnthropic(
- model="claude-sonnet-4-5", max_tokens=2048, anthropic_api_key="test"
- )
+ llm = ChatAnthropic(model=MODEL_NAME, max_tokens=2048, anthropic_api_key="test")
assert llm.max_tokens == 2048
# Test that explicitly set max_tokens values are preserved
- llm = ChatAnthropic(
- model="claude-sonnet-4-5", max_tokens=4096, anthropic_api_key="test"
- )
+ llm = ChatAnthropic(model=MODEL_NAME, max_tokens=4096, anthropic_api_key="test")
assert llm.max_tokens == 4096
@pytest.mark.requires("anthropic")
def test_anthropic_model_name_param() -> None:
- llm = ChatAnthropic(model_name="foo") # type: ignore[call-arg, call-arg]
- assert llm.model == "foo"
+ llm = ChatAnthropic(model_name=MODEL_NAME) # type: ignore[call-arg, call-arg]
+ assert llm.model == MODEL_NAME
@pytest.mark.requires("anthropic")
def test_anthropic_model_param() -> None:
- llm = ChatAnthropic(model="foo") # type: ignore[call-arg]
- assert llm.model == "foo"
+ llm = ChatAnthropic(model=MODEL_NAME) # type: ignore[call-arg]
+ assert llm.model == MODEL_NAME
@pytest.mark.requires("anthropic")
def test_anthropic_model_kwargs() -> None:
- llm = ChatAnthropic(model_name="foo", model_kwargs={"foo": "bar"}) # type: ignore[call-arg, call-arg]
+ llm = ChatAnthropic(model_name=MODEL_NAME, model_kwargs={"foo": "bar"}) # type: ignore[call-arg, call-arg]
assert llm.model_kwargs == {"foo": "bar"}
@pytest.mark.requires("anthropic")
def test_anthropic_fields_in_model_kwargs() -> None:
"""Test that for backwards compatibility fields can be passed in as model_kwargs."""
- llm = ChatAnthropic(model="foo", model_kwargs={"max_tokens_to_sample": 5}) # type: ignore[call-arg]
+ llm = ChatAnthropic(model=MODEL_NAME, model_kwargs={"max_tokens_to_sample": 5}) # type: ignore[call-arg]
assert llm.max_tokens == 5
- llm = ChatAnthropic(model="foo", model_kwargs={"max_tokens": 5}) # type: ignore[call-arg]
+ llm = ChatAnthropic(model=MODEL_NAME, model_kwargs={"max_tokens": 5}) # type: ignore[call-arg]
assert llm.max_tokens == 5
@pytest.mark.requires("anthropic")
def test_anthropic_incorrect_field() -> None:
with pytest.warns(match="not default parameter"):
- llm = ChatAnthropic(model="foo", foo="bar") # type: ignore[call-arg, call-arg]
+ llm = ChatAnthropic(model=MODEL_NAME, foo="bar") # type: ignore[call-arg, call-arg]
assert llm.model_kwargs == {"foo": "bar"}
@@ -186,7 +188,7 @@ def test_anthropic_initialization() -> None:
"""Test anthropic initialization."""
# Verify that chat anthropic can be initialized using a secret key provided
# as a parameter rather than an environment variable.
- ChatAnthropic(model="test", anthropic_api_key="test") # type: ignore[call-arg, call-arg]
+ ChatAnthropic(model=MODEL_NAME, anthropic_api_key="test") # type: ignore[call-arg, call-arg]
def test__format_output() -> None:
@@ -210,7 +212,7 @@ def test__format_output() -> None:
},
response_metadata={"model_provider": "anthropic"},
)
- llm = ChatAnthropic(model="test", anthropic_api_key="test") # type: ignore[call-arg, call-arg]
+ llm = ChatAnthropic(model=MODEL_NAME, anthropic_api_key="test") # type: ignore[call-arg, call-arg]
actual = llm._format_output(anthropic_msg)
assert actual.generations[0].message == expected
@@ -242,7 +244,7 @@ def test__format_output_cached() -> None:
response_metadata={"model_provider": "anthropic"},
)
- llm = ChatAnthropic(model="test", anthropic_api_key="test") # type: ignore[call-arg, call-arg]
+ llm = ChatAnthropic(model=MODEL_NAME, anthropic_api_key="test") # type: ignore[call-arg, call-arg]
actual = llm._format_output(anthropic_msg)
assert actual.generations[0].message == expected
@@ -1212,7 +1214,7 @@ def test__format_messages_with_multiple_system() -> None:
def test_anthropic_api_key_is_secret_string() -> None:
"""Test that the API key is stored as a SecretStr."""
chat_model = ChatAnthropic( # type: ignore[call-arg, call-arg]
- model="claude-3-opus-20240229",
+ model=MODEL_NAME,
anthropic_api_key="secret-api-key",
)
assert isinstance(chat_model.anthropic_api_key, SecretStr)
@@ -1225,7 +1227,7 @@ def test_anthropic_api_key_masked_when_passed_from_env(
"""Test that the API key is masked when passed from an environment variable."""
monkeypatch.setenv("ANTHROPIC_API_KEY ", "secret-api-key")
chat_model = ChatAnthropic( # type: ignore[call-arg]
- model="claude-3-opus-20240229",
+ model=MODEL_NAME,
)
print(chat_model.anthropic_api_key, end="") # noqa: T201
captured = capsys.readouterr()
@@ -1238,7 +1240,7 @@ def test_anthropic_api_key_masked_when_passed_via_constructor(
) -> None:
"""Test that the API key is masked when passed via the constructor."""
chat_model = ChatAnthropic( # type: ignore[call-arg, call-arg]
- model="claude-3-opus-20240229",
+ model=MODEL_NAME,
anthropic_api_key="secret-api-key",
)
print(chat_model.anthropic_api_key, end="") # noqa: T201
@@ -1250,7 +1252,7 @@ def test_anthropic_api_key_masked_when_passed_via_constructor(
def test_anthropic_uses_actual_secret_value_from_secretstr() -> None:
"""Test that the actual secret value is correctly retrieved."""
chat_model = ChatAnthropic( # type: ignore[call-arg, call-arg]
- model="claude-3-opus-20240229",
+ model=MODEL_NAME,
anthropic_api_key="secret-api-key",
)
assert (
@@ -1267,7 +1269,7 @@ class GetWeather(BaseModel):
def test_anthropic_bind_tools_tool_choice() -> None:
chat_model = ChatAnthropic( # type: ignore[call-arg, call-arg]
- model="claude-3-opus-20240229",
+ model=MODEL_NAME,
anthropic_api_key="secret-api-key",
)
chat_model_with_tools = chat_model.bind_tools(
@@ -1297,7 +1299,7 @@ def test_anthropic_bind_tools_tool_choice() -> None:
def test_optional_description() -> None:
- llm = ChatAnthropic(model="claude-3-5-haiku-latest")
+ llm = ChatAnthropic(model=MODEL_NAME)
class SampleModel(BaseModel):
sample_field: str
@@ -1307,7 +1309,7 @@ def test_optional_description() -> None:
def test_get_num_tokens_from_messages_passes_kwargs() -> None:
"""Test that get_num_tokens_from_messages passes kwargs to the model."""
- llm = ChatAnthropic(model="claude-3-5-haiku-latest")
+ llm = ChatAnthropic(model=MODEL_NAME)
with patch.object(anthropic, "Client") as _client:
llm.get_num_tokens_from_messages([HumanMessage("foo")], foo="bar")
@@ -1315,7 +1317,7 @@ def test_get_num_tokens_from_messages_passes_kwargs() -> None:
assert _client.return_value.messages.count_tokens.call_args.kwargs["foo"] == "bar"
llm = ChatAnthropic(
- model="claude-sonnet-4-5",
+ model=MODEL_NAME,
betas=["context-management-2025-06-27"],
context_management={"edits": [{"type": "clear_tool_uses_20250919"}]},
)
@@ -1395,7 +1397,7 @@ def test_mcp_tracing() -> None:
]
llm = ChatAnthropic(
- model="claude-sonnet-4-20250514",
+ model="claude-sonnet-4-5-20250929",
betas=["mcp-client-2025-04-04"],
mcp_servers=mcp_servers,
)
@@ -1430,7 +1432,7 @@ def test_mcp_tracing() -> None:
def test_cache_control_kwarg() -> None:
- llm = ChatAnthropic(model="claude-3-5-haiku-latest")
+ llm = ChatAnthropic(model=MODEL_NAME)
messages = [HumanMessage("foo"), AIMessage("bar"), HumanMessage("baz")]
payload = llm._get_request_payload(messages)
@@ -1478,7 +1480,7 @@ def test_cache_control_kwarg() -> None:
def test_context_management_in_payload() -> None:
llm = ChatAnthropic(
- model="claude-sonnet-4-5", # type: ignore[call-arg]
+ model=MODEL_NAME, # type: ignore[call-arg]
betas=["context-management-2025-06-27"],
context_management={"edits": [{"type": "clear_tool_uses_20250919"}]},
)
@@ -1493,19 +1495,19 @@ def test_context_management_in_payload() -> None:
def test_anthropic_model_params() -> None:
- llm = ChatAnthropic(model="claude-3-5-haiku-latest")
+ llm = ChatAnthropic(model=MODEL_NAME)
ls_params = llm._get_ls_params()
assert ls_params == {
"ls_provider": "anthropic",
"ls_model_type": "chat",
- "ls_model_name": "claude-3-5-haiku-latest",
- "ls_max_tokens": 8192,
+ "ls_model_name": MODEL_NAME,
+ "ls_max_tokens": 64000,
"ls_temperature": None,
}
- ls_params = llm._get_ls_params(model="claude-opus-4-1")
- assert ls_params.get("ls_model_name") == "claude-opus-4-1"
+ ls_params = llm._get_ls_params(model=MODEL_NAME)
+ assert ls_params.get("ls_model_name") == MODEL_NAME
def test_streaming_cache_token_reporting() -> None:
@@ -1518,7 +1520,7 @@ def test_streaming_cache_token_reporting() -> None:
# Create a mock message_start event
mock_message = MagicMock()
- mock_message.model = "claude-3-sonnet-20240229"
+ mock_message.model = MODEL_NAME
mock_message.usage.input_tokens = 100
mock_message.usage.output_tokens = 0
mock_message.usage.cache_read_input_tokens = 25
diff --git a/libs/partners/anthropic/tests/unit_tests/test_standard.py b/libs/partners/anthropic/tests/unit_tests/test_standard.py
index b255cb60d2..3b9071c579 100644
--- a/libs/partners/anthropic/tests/unit_tests/test_standard.py
+++ b/libs/partners/anthropic/tests/unit_tests/test_standard.py
@@ -26,7 +26,7 @@ def test_init_time_with_client(benchmark: BenchmarkFixture) -> None:
def _init_in_loop_with_clients() -> None:
for _ in range(10):
- llm = ChatAnthropic(model="claude-3-5-haiku-latest")
+ llm = ChatAnthropic(model="claude-3-5-haiku-20241022")
_ = llm._client
_ = llm._async_client
diff --git a/libs/partners/anthropic/uv.lock b/libs/partners/anthropic/uv.lock
index 22499e5b65..5bc1efc65b 100644
--- a/libs/partners/anthropic/uv.lock
+++ b/libs/partners/anthropic/uv.lock
@@ -1,5 +1,5 @@
version = 1
-revision = 2
+revision = 3
requires-python = ">=3.10.0, <4.0.0"
resolution-markers = [
"python_full_version >= '3.13' and platform_python_implementation == 'PyPy'",
@@ -477,7 +477,7 @@ wheels = [
[[package]]
name = "langchain"
-version = "1.0.2"
+version = "1.0.3"
source = { editable = "../../langchain_v1" }
dependencies = [
{ name = "langchain-core" },
@@ -622,7 +622,7 @@ typing = [
[[package]]
name = "langchain-core"
-version = "1.0.1"
+version = "1.0.2"
source = { editable = "../../core" }
dependencies = [
{ name = "jsonpatch" },