nemoguardrails.llm.openai_reasoning

View as Markdown

Module Contents

Functions

NameDescription
apply_openai_reasoning_overridesDrop unsupported params and remap max_tokens for OpenAI reasoning models.
is_openai_reasoning_modelTrue for OpenAI reasoning models (o1/o3/o4 series, gpt-5+).

Data

_REASONING_DROP_PARAMS

API

nemoguardrails.llm.openai_reasoning.apply_openai_reasoning_overrides(
params: typing.Dict[str, typing.Any]
) -> typing.Dict[str, typing.Any]

Drop unsupported params and remap max_tokens for OpenAI reasoning models.

OpenAI reasoning models (o-series, gpt-5+) require max_completion_tokens instead of max_tokens and reject temperature / stop on most members of the family. This helper applies the rename and the drop list in one place so the DefaultFramework OpenAI client and the LangChain adapter cannot drift on what they strip.

The drop list is deliberately limited to the params OpenAI’s API itself is documented to reject (verified by the live probe in tests/integrations/langchain/test_openai_param_filter.py); other sometimes-rejected params (top_p, presence_penalty, etc.) are accepted by some reasoning models in the family and are left to the caller.

Returns a new dict; does not mutate the input.

Drops: temperature, stop.

Renames: max_tokens -> max_completion_tokens (only if max_tokens carries a non-None value and max_completion_tokens is not already present, so an explicit max_completion_tokens always wins and an unset max_tokens is not promoted to a null wire field).

nemoguardrails.llm.openai_reasoning.is_openai_reasoning_model(
model_name: str
) -> bool

True for OpenAI reasoning models (o1/o3/o4 series, gpt-5+).

Used to decide whether to strip parameters that OpenAI rejects on these models (temperature, stop, etc.) and how to remap others (max_tokens -> max_completion_tokens). Shared by the DefaultFramework OpenAI client and the LangChain adapter so the two paths cannot drift.

nemoguardrails.llm.openai_reasoning._REASONING_DROP_PARAMS = frozenset({'temperature', 'stop'})