langchain - ✅(Solved) Fix bug(core): _get_ls_params silently drops integer temperature values from LangSmith tracing [2 pull requests, 1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#35300Fetched 2026-04-08 00:26:47
View on GitHub
Comments
1
Participants
1
Timeline
10
Reactions
0
Participants
Timeline (top)
labeled ×4cross-referenced ×2closed ×1commented ×1

BaseChatModel._get_ls_params() and BaseLLM._get_ls_params() use isinstance(kwargs["temperature"], float) to check the temperature parameter before adding it to LangSmith tracing metadata. However, in Python, isinstance(0, float) is False — integer values like temperature=0 or temperature=1 are silently dropped from tracing.

This is a silent data loss bug: no error or warning is raised, the temperature value simply doesn't appear in LangSmith traces when passed as an integer.

Affected Code. libs/core/langchain_core/language_models/chat_models.py

(lines 815-818):

if "temperature" in kwargs and isinstance(kwargs["temperature"], float):
    ls_params["ls_temperature"] = kwargs["temperature"]
elif hasattr(self, "temperature") and isinstance(self.temperature, float):
    ls_params["ls_temperature"] = self.temperature
libs/core/langchain_core/language_models/llms.py

(lines 354-357):

if "temperature" in kwargs and isinstance(kwargs["temperature"], float):
    ls_params["ls_temperature"] = kwargs["temperature"]
elif hasattr(self, "temperature") and isinstance(self.temperature, float):
    ls_params["ls_temperature"] = self.temperature

Root Cause ;

isinstance(0, float) returns False in Python. int is not a subclass of float. Note the inconsistency: the adjacent max_tokens check correctly uses isinstance(kwargs["max_tokens"], int), while temperature only checks for float.

Suggested Fix Change isinstance(..., float) to isinstance(..., (int, float)) in all 4 locations (2 in chat_models.py, 2 in llms.py):

- if "temperature" in kwargs and isinstance(kwargs["temperature"], float):
+ if "temperature" in kwargs and isinstance(kwargs["temperature"], (int, float)):
      ls_params["ls_temperature"] = kwargs["temperature"]
- elif hasattr(self, "temperature") and isinstance(self.temperature, float):
+ elif hasattr(self, "temperature") and isinstance(self.temperature, (int, float)):
      ls_params["ls_temperature"] = self.temperature

Existing tests should also be updated to cover integer temperature kwargs (currently only temperature=0.2 is tested).

Impact

  • High: temperature=0 is one of the most common settings for deterministic LLM outputs
  • Silent failure: Users won't know their temperature values are missing from LangSmith traces
  • Affects all language models (both BaseChatModel and BaseLLM)

Error Message

Error Message and Stack Trace (if applicable)

This is a silent data loss bug: no error or warning is raised, the temperature value simply doesn't appear in LangSmith traces when passed as an integer.

Root Cause

Root Cause ;

Fix Action

Fix / Workaround

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Other Dependencies

httpx: 0.28.1 jsonpatch: 1.33 orjson: 3.11.7 packaging: 26.0 pydantic: 2.12.5 pyyaml: 6.0.3 requests: 2.32.5 requests-toolbelt: 1.0.0 tenacity: 9.1.4 typing-extensions: 4.15.0 uuid-utils: 0.14.0 xxhash: 3.6.0 zstandard: 0.25.0

PR fix notes

PR #35302: fix(core): accept int temperature in _get_ls_params for LangSmith tracing

Description (problem / solution / changelog)

Description

Fixes #35300

BaseChatModel._get_ls_params() and BaseLLM._get_ls_params() use isinstance(kwargs["temperature"], float) to check the temperature parameter before adding it to LangSmith tracing metadata.

isinstance(0, float) is False so integer temperature values like temperature=0 or temperature=1 are silently dropped from traces.

Changed to isinstance(..., (int, float)) in all 4 locations.

Added regression tests covering integer temperature kwargs.

Changed files

  • libs/core/langchain_core/language_models/chat_models.py (modified, +4/-2)
  • libs/core/langchain_core/language_models/llms.py (modified, +4/-2)
  • libs/core/tests/unit_tests/language_models/chat_models/test_base.py (modified, +7/-0)
  • libs/core/tests/unit_tests/language_models/llms/test_base.py (modified, +7/-0)

PR #35317: fix(core): accept integer temperature values in _get_ls_params

Description (problem / solution / changelog)

Summary

  • _get_ls_params in both BaseChatModel and BaseLLM used isinstance(..., float) to validate the temperature parameter, which silently dropped integer values like temperature=0 or temperature=1 from LangSmith tracing metadata.
  • Changed to isinstance(..., (int, float)) so integer temperatures are correctly propagated.
  • Added test coverage for integer temperature values in both chat model and LLM test suites.

Closes #35300

Test plan

  • New tests test_get_ls_params_int_temperature pass in both chat_models/test_base.py and llms/test_base.py
  • Existing test_get_ls_params tests still pass (no regression)
  • ruff check and ruff format --check pass on all changed files

[!NOTE] This contribution was made with assistance from an AI agent (Claude Code).

🤖 Generated with Claude Code

Changed files

  • libs/core/langchain_core/language_models/chat_models.py (modified, +4/-2)
  • libs/core/langchain_core/language_models/llms.py (modified, +4/-2)
  • libs/core/tests/unit_tests/language_models/chat_models/test_base.py (modified, +34/-0)
  • libs/core/tests/unit_tests/language_models/llms/test_base.py (modified, +35/-0)

Code Example

from langchain_core.language_models.chat_models import BaseChatModel
from typing import Any
from langchain_core.messages import BaseMessage, AIMessage
from langchain_core.outputs import ChatResult, ChatGeneration
from langchain_core.callbacks import CallbackManagerForLLMRun

class TestModel(BaseChatModel):
    model: str = "test"
    temperature: float = 0.1
    max_tokens: int = 1024

    def _generate(self, messages: list[BaseMessage], stop: list[str] | None = None,
                  run_manager: CallbackManagerForLLMRun | None = None, **kwargs: Any) -> ChatResult:
        return ChatResult(generations=[ChatGeneration(message=AIMessage(content="test"))])

    @property
    def _llm_type(self) -> str:
        return "test"

model = TestModel()

# BUG: integer temperature is silently dropped
ls_params = model._get_ls_params(temperature=0)
print("ls_temperature" in ls_params)  # False — temperature=0 is lost!

# Works fine with float
ls_params = model._get_ls_params(temperature=0.0)
print("ls_temperature" in ls_params)  # True

# Inconsistency: max_tokens with int works fine
ls_params = model._get_ls_params(max_tokens=2048)
print("ls_max_tokens" in ls_params)  # True

---



---

if "temperature" in kwargs and isinstance(kwargs["temperature"], float):
    ls_params["ls_temperature"] = kwargs["temperature"]
elif hasattr(self, "temperature") and isinstance(self.temperature, float):
    ls_params["ls_temperature"] = self.temperature
libs/core/langchain_core/language_models/llms.py

---

if "temperature" in kwargs and isinstance(kwargs["temperature"], float):
    ls_params["ls_temperature"] = kwargs["temperature"]
elif hasattr(self, "temperature") and isinstance(self.temperature, float):
    ls_params["ls_temperature"] = self.temperature

---

- if "temperature" in kwargs and isinstance(kwargs["temperature"], float):
+ if "temperature" in kwargs and isinstance(kwargs["temperature"], (int, float)):
      ls_params["ls_temperature"] = kwargs["temperature"]
- elif hasattr(self, "temperature") and isinstance(self.temperature, float):
+ elif hasattr(self, "temperature") and isinstance(self.temperature, (int, float)):
      ls_params["ls_temperature"] = self.temperature
RAW_BUFFERClick to expand / collapse

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Related Issues / PRs

No response

Reproduction Steps / Example Code (Python)

from langchain_core.language_models.chat_models import BaseChatModel
from typing import Any
from langchain_core.messages import BaseMessage, AIMessage
from langchain_core.outputs import ChatResult, ChatGeneration
from langchain_core.callbacks import CallbackManagerForLLMRun

class TestModel(BaseChatModel):
    model: str = "test"
    temperature: float = 0.1
    max_tokens: int = 1024

    def _generate(self, messages: list[BaseMessage], stop: list[str] | None = None,
                  run_manager: CallbackManagerForLLMRun | None = None, **kwargs: Any) -> ChatResult:
        return ChatResult(generations=[ChatGeneration(message=AIMessage(content="test"))])

    @property
    def _llm_type(self) -> str:
        return "test"

model = TestModel()

# BUG: integer temperature is silently dropped
ls_params = model._get_ls_params(temperature=0)
print("ls_temperature" in ls_params)  # False — temperature=0 is lost!

# Works fine with float
ls_params = model._get_ls_params(temperature=0.0)
print("ls_temperature" in ls_params)  # True

# Inconsistency: max_tokens with int works fine
ls_params = model._get_ls_params(max_tokens=2048)
print("ls_max_tokens" in ls_params)  # True

Error Message and Stack Trace (if applicable)

Description

BaseChatModel._get_ls_params() and BaseLLM._get_ls_params() use isinstance(kwargs["temperature"], float) to check the temperature parameter before adding it to LangSmith tracing metadata. However, in Python, isinstance(0, float) is False — integer values like temperature=0 or temperature=1 are silently dropped from tracing.

This is a silent data loss bug: no error or warning is raised, the temperature value simply doesn't appear in LangSmith traces when passed as an integer.

Affected Code. libs/core/langchain_core/language_models/chat_models.py

(lines 815-818):

if "temperature" in kwargs and isinstance(kwargs["temperature"], float):
    ls_params["ls_temperature"] = kwargs["temperature"]
elif hasattr(self, "temperature") and isinstance(self.temperature, float):
    ls_params["ls_temperature"] = self.temperature
libs/core/langchain_core/language_models/llms.py

(lines 354-357):

if "temperature" in kwargs and isinstance(kwargs["temperature"], float):
    ls_params["ls_temperature"] = kwargs["temperature"]
elif hasattr(self, "temperature") and isinstance(self.temperature, float):
    ls_params["ls_temperature"] = self.temperature

Root Cause ;

isinstance(0, float) returns False in Python. int is not a subclass of float. Note the inconsistency: the adjacent max_tokens check correctly uses isinstance(kwargs["max_tokens"], int), while temperature only checks for float.

Suggested Fix Change isinstance(..., float) to isinstance(..., (int, float)) in all 4 locations (2 in chat_models.py, 2 in llms.py):

- if "temperature" in kwargs and isinstance(kwargs["temperature"], float):
+ if "temperature" in kwargs and isinstance(kwargs["temperature"], (int, float)):
      ls_params["ls_temperature"] = kwargs["temperature"]
- elif hasattr(self, "temperature") and isinstance(self.temperature, float):
+ elif hasattr(self, "temperature") and isinstance(self.temperature, (int, float)):
      ls_params["ls_temperature"] = self.temperature

Existing tests should also be updated to cover integer temperature kwargs (currently only temperature=0.2 is tested).

Impact

  • High: temperature=0 is one of the most common settings for deterministic LLM outputs
  • Silent failure: Users won't know their temperature values are missing from LangSmith traces
  • Affects all language models (both BaseChatModel and BaseLLM)

System Info

System Information

OS: Darwin OS Version: Darwin Kernel Version 25.2.0: Tue Nov 18 21:08:48 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T8132 Python Version: 3.13.0rc3 (v3.13.0rc3:fae84c70fbd, Oct 1 2024, 00:10:10) [Clang 15.0.0 (clang-1500.3.9.4)]

Package Information

langchain_core: 1.2.13 langsmith: 0.7.4

Optional packages not installed

langserve

Other Dependencies

httpx: 0.28.1 jsonpatch: 1.33 orjson: 3.11.7 packaging: 26.0 pydantic: 2.12.5 pyyaml: 6.0.3 requests: 2.32.5 requests-toolbelt: 1.0.0 tenacity: 9.1.4 typing-extensions: 4.15.0 uuid-utils: 0.14.0 xxhash: 3.6.0 zstandard: 0.25.0

extent analysis

Fix Plan

Change isinstance Checks to Accept Both int and float

Update the isinstance checks in BaseChatModel and BaseLLM to accept both int and float values.

Code Changes

# libs/core/langchain_core/language_models/chat_models.py
if "temperature" in kwargs and isinstance(kwargs["temperature"], (int, float)):
    ls_params["ls_temperature"] = kwargs["temperature"]
elif hasattr(self, "temperature") and isinstance(self.temperature, (int, float)):
    ls_params["ls_temperature"] = self.temperature

# libs/core/langchain_core/language_models/llms.py
if "temperature" in kwargs and isinstance(kwargs["temperature"], (int, float)):
    ls_params["ls_temperature"] = kwargs["temperature"]
elif hasattr(self, "temperature") and isinstance(self.temperature, (int, float)):
    ls_params["ls_temperature"] = self.temperature

Update Tests to Cover Integer Temperature Kwargs

Update the existing tests to cover integer temperature kwargs, such as temperature=0 or temperature=1.

Example Test

import unittest
from langchain_core.language_models.chat_models import BaseChatModel

class TestModel(BaseChatModel):
    model: str = "test"
    temperature: int = 0  # Update temperature to an integer value

    def test_get_ls_params(self):
        ls_params = self._get_ls_params(temperature=self.temperature)
        self.assertIn("ls_temperature", ls_params)

Verification

  1. Run the updated code with integer temperature values (e.g., temperature=0 or temperature=1).
  2. Verify that the temperature value is correctly added to the LangSmith tracing metadata.
  3. Run the updated tests to ensure that they pass with integer temperature values.

Extra Tips

  • Make sure to update the documentation to reflect the change in behavior

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

langchain - ✅(Solved) Fix bug(core): _get_ls_params silently drops integer temperature values from LangSmith tracing [2 pull requests, 1 comments, 1 participants]