#867·kotaemon

[BUG] `LCAnthropicChat` hardcodes `temperature=0.7`, which current Claude models reject with HTTP 400

Author: viggotwCreated Sep 18, 2026Updated Sep 18, 2026
Labelsbug

Description

Environment

| | ||---|---| | kotaemon version | 0.12.0 | | langchain-anthropic | 0.1.23 (as pinned) | | Model configured | claude-sonnet-5 |

Symptom

Configuring any current Claude model and clicking Test connection fails:

Connection failed. Got error: Error code: 400 - {'type': 'error', 'error':
{'type': 'invalid_request_error', 'message': '`temperature` is deprecated for
this model.'}, 'request_id': 'req_...'}

The API key is valid — the request authenticates successfully and the error concerns the request body, not credentials.

Root cause

Current Claude models (Sonnet 5, Opus 5, Opus 4.8, Opus 4.7, and the Fable family) removed the sampling parameters temperature, top_p and top_k. Sending any of them is rejected outright rather than ignored. Opus 4.6 / Sonnet 4.6 and older still accept them.

libs/kotaemon/kotaemon/llms/chats/langchain_based.py:264-276 hardcodes a temperature and always forwards it:

python
def __init__(
    self,
    api_key: str | None = None,
    model_name: str | None = None,
    temperature: float = 0.7,        # <- line 268, always sent
    **params,
):
    super().__init__(
        api_key=api_key,
        model_name=model_name,
        temperature=temperature,
        **params,
    )

This is the only source of the parameter. langchain_anthropic strips None values before building the request (chat_models.py, _get_request_payload: return {k: v for k, v in payload.items() if v is not None}), and ChatAnthropic.temperature already defaults to None.

Reproduced without making an API call, by inspecting the outgoing payload:

python
from kotaemon.llms.chats import LCAnthropicChat
c = LCAnthropicChat(api_key="dummy", model_name="claude-sonnet-5")
print(c._obj._get_request_payload([{"role": "user", "content": "hi"}]))
temperature on the wire: 0.7
payload keys: ['max_tokens', 'messages', 'model', 'temperature']

Suggested fix

One line — default to None so the parameter is omitted unless explicitly set:

diff
--- a/libs/kotaemon/kotaemon/llms/chats/langchain_based.py
+++ b/libs/kotaemon/kotaemon/llms/chats/langchain_based.py
@@ -265,7 +265,7 @@ class LCAnthropicChat(LCChatMixin, ChatLLM):
         self,
         api_key: str | None = None,
         model_name: str | None = None,
-        temperature: float = 0.7,
+        temperature: float | None = None,
         **params,
     ):

Verified both directions after the change:

default  -> temperature: '<ABSENT>'  | keys: ['max_tokens', 'messages', 'model']
explicit -> temperature: 0.3

Omitted by default, still honoured when set — so older models that accept it are unaffected. The other four wrappers in the same file (lines 197, 226, 312, 344) share the pattern but target providers that still accept temperature, so they need no change.

Two related points

Default model is outdated. flowsettings.py:232-238 still defaults to claude-3-5-sonnet-20240620. Worth refreshing to a current model — which makes fixing the temperature default a prerequisite rather than optional.

Forced tool use will be the next failure. langchain_based.py:261-262:

python
def _get_tool_call_kwargs(self):
    return {"tool_choice": {"type": "any"}}

This is used by the citation and question-decomposition pipelines. Forced tool use (tool_choice any / tool) is rejected with a 400 on the newest Claude models (Fable 5.1), though it still works on Sonnet 5 and Opus 5. The recommended replacement is {"type": "auto"} plus strict: true on the tool definition, or structured outputs where the forced call only existed to get JSON back.

Reproduction steps

bash
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

Screenshots

bash
![DESCRIPTION](LINK.png)

Logs

bash

Browsers

No response

OS

No response

Additional information

No response