-
Notifications
You must be signed in to change notification settings - Fork 563
fix(llm): filter temperature parameter for OpenAI reasoning models #1526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
OpenAI reasoning models (o1, o3, gpt-5 series excluding gpt-5-chat) only support `temperature=1`. When NeMo Guardrails uses `.bind(temperature=0.001)` for deterministic tasks like self-check input/output, the API returns an error: ``` Unsupported value: 'temperature' does not support 0.001 with this model. Only the default (1) value is supported. ``` This happens because LangChain's `ChatOpenAI` handles temperature restrictions at initialization time (setting `temperature=None` for reasoning models), but `.bind()` bypasses this protection and passes the temperature directly to the API. - Added `_filter_params_for_openai_reasoning_models()` function that: - Detects reasoning models by name (o1*, o3*, gpt-5* excluding gpt-5-chat) - Removes the `temperature` parameter before binding for these models - Follows the same pattern as LangChain's `validate_temperature` validator
Greptile OverviewGreptile SummaryThis PR fixes a critical bug where OpenAI reasoning models (o1, o3, gpt-5 series excluding gpt-5-chat) fail with Key Changes:
Issues Found:
|
| Filename | Score | Overview |
|---|---|---|
| nemoguardrails/actions/llm/utils.py | 4/5 | Added _filter_params_for_openai_reasoning_models() to remove temperature param for o1/o3/gpt-5 models before binding, fixing API errors |
| tests/test_actions_llm_utils.py | 5/5 | Comprehensive test coverage with 13 test cases covering reasoning models (o1, o3, gpt-5*), regular models (gpt-4*), and edge cases |
Sequence Diagram
sequenceDiagram
participant User
participant LLMCall as llm_call()
participant Filter as _filter_params_for_openai_reasoning_models()
participant LLM as LangChain LLM
participant API as OpenAI API
User->>LLMCall: call with llm_params={temperature: 0.001}
LLMCall->>Filter: filter params for reasoning model
Filter->>Filter: check if model is o1/o3/gpt-5*
alt is reasoning model
Filter->>Filter: remove temperature parameter
Filter-->>LLMCall: {max_tokens: ...} (temp removed)
else not reasoning model
Filter-->>LLMCall: {temperature: 0.001, max_tokens: ...}
end
LLMCall->>LLM: llm.bind(**filtered_params)
LLM->>API: API call with allowed params
API-->>LLM: success response
LLM-->>LLMCall: response
LLMCall-->>User: generated text
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional Comments (3)
-
nemoguardrails/library/hallucination/actions.py, line 82 (link)logic: this
.bind(temperature=1.0)call will fail with OpenAI reasoning models since it bypasses the_filter_params_for_openai_reasoning_models()function. Consider importing and using the filter function here or calling throughllm_call() -
nemoguardrails/evaluate/evaluate_factcheck.py, line 98 (link)logic: this
.bind(temperature=0.8)call will fail with OpenAI reasoning models. Consider importing and using_filter_params_for_openai_reasoning_models()function -
nemoguardrails/evaluate/evaluate_hallucination.py, line 74 (link)logic: if
llm_paramscontainstemperature, this.bind()call will fail with OpenAI reasoning models. Consider importing and using_filter_params_for_openai_reasoning_models()function
2 files reviewed, 4 comments
| is_openai_reasoning_model = ( | ||
| model_name.startswith("o1") | ||
| or model_name.startswith("o3") | ||
| or (model_name.startswith("gpt-5") and "chat" not in model_name) | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: verify this detection logic handles future OpenAI reasoning models (e.g., gpt-6 or o4 series) that may have similar temperature restrictions
Prompt To Fix With AI
This is a comment left during a code review.
Path: nemoguardrails/actions/llm/utils.py
Line: 154:158
Comment:
**style:** verify this detection logic handles future OpenAI reasoning models (e.g., gpt-6 or o4 series) that may have similar temperature restrictions
How can I resolve this? If you propose a fix, please make it concise.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
OpenAI reasoning models (o1, o3, gpt-5 series excluding gpt-5-chat) only support
temperature=1. When NeMo Guardrails uses.bind(temperature=0.001)for deterministic tasks like self-check input/output, the API returns an error:This happens because LangChain's
ChatOpenAIhandles temperature restrictions at initialization time (settingtemperature=Nonefor reasoning models), but.bind()bypasses this protection and passes the temperature directly to the API._filter_params_for_openai_reasoning_models()function that:temperatureparameter before binding for these modelsvalidate_temperaturevalidatorto repro
or
Fixes: #1512 #992