From adf532d260bbbbb334a4893cae8a8b70551b22b8 Mon Sep 17 00:00:00 2001 From: Alex Castillo Date: Wed, 21 Oct 2026 14:23:24 -0400 Subject: [PATCH] fix(anthropic): say what Anthropic documents in the sampling parameter deprecation warning Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 1 + chatlas/_provider_anthropic.py | 17 +++++++++++------ tests/test_set_model_params.py | 24 ++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 040d34c8..990741cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug fixes +* The deprecation warning for `temperature`, `top_p` and `top_k` on `ChatAnthropic()` no longer says these parameters have no effect on current models. Anthropic's deprecation page says Claude 4.7 and later models return a 400 error when they are set to a non-default value, and that API version 2026-10-21 removes them for every model; the warning now says so. What is forwarded is unchanged. * `ChatOllama()` can now be created without a `model`, so `ChatOllama().list_models()` works. Sending a message without a model still raises an error that lists the available models. (#166) * `ChatGoogle()` now reports `finish_reason == "content_filter"` for Gemini's `IMAGE_SAFETY`, `IMAGE_PROHIBITED_CONTENT`, `IMAGE_RECITATION` and `LANGUAGE` finish reasons, instead of passing the raw Gemini string through, and reports `"tool_use"` (rather than `"success"`) when a turn ends with a tool request, as `ChatOpenAI()` does. (#473) * The error raised for a tool request with invalid JSON arguments from `ChatOpenAI()` and `ChatOpenAICompletions()` (and the providers built on them) now shows the offending arguments, instead of the literal text `{args}`. diff --git a/chatlas/_provider_anthropic.py b/chatlas/_provider_anthropic.py index 3a0b4e0e..d8bc0a0b 100644 --- a/chatlas/_provider_anthropic.py +++ b/chatlas/_provider_anthropic.py @@ -799,15 +799,20 @@ def translate_model_params(self, params: StandardModelParams) -> "SubmitInputArg res: "SubmitInputArgs" = {} # anthropic>=1.0 removed these sampling parameters from the request - # schema; current models ignore them. Forward them via `extra_body` - # so older models that still honor them keep working. + # schema; Claude 4.7 and later reject non-default values with a 400. + # Forward them via `extra_body` so older models that still honor them + # keep working. removed = [p for p in ("temperature", "top_p", "top_k") if p in params] if removed: warnings.warn( - f"The {', '.join(removed)} sampling parameter(s) no longer have " - "an effect on current Anthropic models. They are forwarded via " - "`extra_body` for older models that still honor them; this " - "forwarding is deprecated and will be removed in a future release.", + f"The {', '.join(removed)} sampling parameter(s) are deprecated by " + "Anthropic: Claude 4.7 and later models return a 400 error when they " + "are set to a non-default value, and API version 2026-10-21 removes " + "them for every model " + "(https://platform.claude.com/docs/en/about-claude/model-deprecations). " + "They are forwarded via `extra_body` for older models that still " + "honor them; this forwarding is deprecated and will be removed in a " + "future release.", DeprecationWarning, stacklevel=2, ) diff --git a/tests/test_set_model_params.py b/tests/test_set_model_params.py index f3d45d17..ae3b1cae 100644 --- a/tests/test_set_model_params.py +++ b/tests/test_set_model_params.py @@ -169,7 +169,10 @@ def test_translate_model_params_anthropic(): "stop_sequences": ["STOP"], } - with pytest.warns(DeprecationWarning, match="no longer have an effect"): + with pytest.warns( + DeprecationWarning, + match="return a 400 error when they are set to a non-default value", + ): result = provider.translate_model_params(params) expected = { @@ -517,7 +520,10 @@ def test_anthropic_model_params_integration(): ) # Test that provider.translate_model_params converts them correctly - with pytest.warns(DeprecationWarning, match="no longer have an effect"): + with pytest.warns( + DeprecationWarning, + match="return a 400 error when they are set to a non-default value", + ): provider_args = chat.provider.translate_model_params( chat._standard_model_params ) @@ -564,3 +570,17 @@ def test_chat_kwargs_with_model_params(): assert kwargs.get("max_tokens") == 100 assert kwargs.get("frequency_penalty") == 0.1 assert kwargs.get("presence_penalty") == 0.3 # Should override chat.chat_kwargs + + +def test_anthropic_sampling_warning_cites_the_deprecation_page(): + """The warning says what Anthropic documents: a 400 on Claude 4.7+, removal in 2026-10-21.""" + provider = ChatAnthropic().provider + + with pytest.warns(DeprecationWarning) as record: + provider.translate_model_params({"temperature": 0.7, "top_k": 50}) + + message = str(record[0].message) + assert message.startswith("The temperature, top_k sampling parameter(s)") + assert "Claude 4.7 and later" in message + assert "2026-10-21" in message + assert "no longer have an effect" not in message