You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG validate_temperature and validate_top_p accept NaN #3605
validate_temperature and validate_top_p in pyrit/prompt_target/common/utils.py accept float("nan"). Both use value < low or value > high, and every comparison with NaN is False, so NaN passes. The neighbouring validate_presence_penalty and validate_frequency_penalty use not low <= value <= high and already reject NaN, and their tests cover it.
Every target that calls these validators accepts a NaN temperature or top_p: OpenAIChatTarget, OpenAIResponseTarget, OpenAICompletionTarget, LiteLLMChatTarget and AzureMLChatTarget. The NaN is stored in the target's identifier. Each send then fails when httpx encodes the request body, with ValueError: Out of range float values are not JSON compliant, instead of the target rejecting the value up front with the usual range message.
Steps to reproduce
frompyrit.prompt_target.common.utilsimportvalidate_temperature, validate_top_pvalidate_temperature(float("nan")) # no errorvalidate_top_p(float("nan")) # no error
inf and -inf are already rejected, because they compare outside the range.
Expected behavior
validate_temperature(float("nan")) and validate_top_p(float("nan")) raise PyritException with the same range messages they use for other out-of-range values, matching the penalty validators.
Proposed fix
Write both checks as not 0 <= temperature <= 2 and not 0 <= top_p <= 1, like the penalty validators, and add nan, inf and -inf cases to tests/unit/prompt_target/test_target_utils.py.
Reproduced on main dd2895d. I'd be happy to open a PR.
Activity