Skip to content

FIX Reject NaN in validate_temperature and validate_top_p - #3606

Open
Shivam Sharma (ShivamSharma43) wants to merge 4 commits into
microsoft:mainfrom
ShivamSharma43:fix/reject-nan-temperature-top-p
Open

Shivam Sharma (ShivamSharma43) wants to merge 4 commits into
microsoft:mainfrom
ShivamSharma43:fix/reject-nan-temperature-top-p

Conversation

@ShivamSharma43

Copy link
Copy Markdown
Contributor

Description

Fixes #3605.

validate_temperature and validate_top_p checked value < low or value > high. Every comparison with NaN is False, so a NaN temperature or top_p passed validation. OpenAIChatTarget, OpenAIResponseTarget, OpenAICompletionTarget, LiteLLMChatTarget and AzureMLChatTarget then stored it in their identifier, and every send failed when httpx encoded the request body (Out of range float values are not JSON compliant).

Changes:

  • Both checks now use not 0 <= value <= high, the same form as validate_presence_penalty and validate_frequency_penalty. NaN is rejected with the existing range message. inf and -inf were already rejected, and finite values behave as before.
  • The docstrings mention NaN.

Tests and Documentation

  • tests/unit/prompt_target/test_target_utils.py: nan, inf and -inf cases for both validators, matching the existing penalty tests. The two nan cases fail on main; the inf cases already passed and document the current behavior.
  • pytest tests/unit/prompt_target -k "temperature or top_p or validat or init": 319 passed, 15 skipped.
  • ruff check, ruff format and ty check pass on the changed files.
  • No documentation changes beyond the docstrings.

🤖 Generated with Claude Code

Both checks were written as `value < low or value > high`, which is False
for NaN, so a NaN temperature or top_p passed validation and only failed
later when httpx refused to encode the request body. Use
`not low <= value <= high` like the presence and frequency penalty
validators.

Fixes microsoft#3605

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 28, 2026 06:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The chained bounds checks reject NaN and infinity while preserving None and the inclusive limits. The focused regression cases cover both validators.

No blocking issues found by code inspection. Tests were not run for this review. AI-assisted review (GitHub Copilot).

@ShivamSharma43

Copy link
Copy Markdown
Contributor Author

The only failing job here is test_hierarchy_traversal_halts_immediately_on_budget_exhaustion, the wall-clock timing test reported in #3608, which fails on other PRs too; #3609 makes it deterministic. Roman Lutz (@romanlutz), could you rerun the failed jobs when you have a moment? #3556 and #3592 went green on a rerun.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG validate_temperature and validate_top_p accept NaN

3 participants