validate_temperature() — langchain Function Reference
Architecture documentation for the validate_temperature() function in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD fe595249_ddf1_7df8_5132_9c3aa50c9bef["validate_temperature()"] 2a683305_667b_3567_cab9_9f77e29d4afa["BaseChatOpenAI"] fe595249_ddf1_7df8_5132_9c3aa50c9bef -->|defined in| 2a683305_667b_3567_cab9_9f77e29d4afa style fe595249_ddf1_7df8_5132_9c3aa50c9bef fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/openai/langchain_openai/chat_models/base.py lines 873–901
def validate_temperature(cls, values: dict[str, Any]) -> Any:
"""Validate temperature parameter for different models.
- gpt-5 models (excluding gpt-5-chat) only allow `temperature=1` or unset
(Defaults to 1)
"""
model = values.get("model_name") or values.get("model") or ""
model_lower = model.lower()
# For o1 models, set temperature=1 if not provided
if model_lower.startswith("o1") and "temperature" not in values:
values["temperature"] = 1
# For gpt-5 models, handle temperature restrictions. Temperature is supported
# by gpt-5-chat and gpt-5 models with reasoning_effort='none' or
# reasoning={'effort': 'none'}.
if (
model_lower.startswith("gpt-5")
and ("chat" not in model_lower)
and values.get("reasoning_effort") != "none"
and (values.get("reasoning") or {}).get("effort") != "none"
):
temperature = values.get("temperature")
if temperature is not None and temperature != 1:
# For gpt-5 (non-chat), only temperature=1 is supported
# So we remove any non-defaults
values.pop("temperature", None)
return values
Domain
Subdomains
Source
Frequently Asked Questions
What does validate_temperature() do?
validate_temperature() is a function in the langchain codebase, defined in libs/partners/openai/langchain_openai/chat_models/base.py.
Where is validate_temperature() defined?
validate_temperature() is defined in libs/partners/openai/langchain_openai/chat_models/base.py at line 873.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free