Repository navigation
fix: reject non-finite Score values - #1189
Chen Yufeiyang (feiiiiii5) wants to merge 1 commit into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eb140eaea2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
| if isinstance(self.score, bool) or not isinstance(self.score, (int, float)): | ||
| raise ValueError(f"score ({self.score}) must be a number between 0 and 1") |
There was a problem hiding this comment.
Normalize boolean scorer returns before enforcing this guard
When an Eval/EvalAsync scorer returns a comparison such as output == expected, OneOrMoreScores explicitly permits the resulting boolean, but await_or_run_scorer passes it unchanged to Score at framework.py:1649. This guard therefore turns both valid outcomes into scorer exceptions, leaving scores missing or replacing them with error-handler scores. Normalize boolean results to 0/1 at the scorer boundaries before enforcing this constructor restriction. The existing True/False runtime cases in type_tests/test_dict_scorers.py, executed by test_types, cover this supported contract.
AGENTS.md reference: AGENTS.md:L150-L150
Useful? React with 👍 / 👎.
eb140ea to
992aa5d
Compare
|
Addressed the Codex finding: |
Summary
Score.__post_init__validated only the[0,1]range.float("nan")passed both comparisons and was stored as a valid score, silently poisoning downstream summary averages (total / count→nan).float("inf")/-float("inf")were already rejected by the range check.Fix
Reject non-finite floats via
math.isfinitebefore the range check, with a descriptiveValueError. The range check and its original message are unchanged.Boolean scores are not rejected:
OneOrMoreScoresexplicitly includesbool, andawait_or_run_scorerpasses a scorer'sTrue/Falsereturn straight intoScore. An earlier revision of this PR rejected booleans; the Codex review correctly flagged that this broke a supported contract (including theTrue/Falseruntime cases intype_tests/test_dict_scorers.py), so it was narrowed to non-finite values only.Verification
unittestmethods insrc/braintrust/test_score.py(the module noxtest_corediscovers): non-finite values rejected;0,1,0.5,True,Falseaccepted and round-tripped.test_score.py+type_tests/test_dict_scorers.py: 28 passed, 8 subtests passed (with the repo's plugin set; the bare interpreter needs brokentypeguard/braintrust/recordingentry points disabled).ruff checkandruff format --checkclean.Behavior change
A
Scoreconstructed with NaN now raisesValueErrorinstead of storing a NaN that corrupts aggregates. All previously valid scores, including boolean scorer returns, behave exactly as before.