-
Notifications
You must be signed in to change notification settings - Fork 0
fix(evaluations): reject boolean scorer scores #92
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: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -866,25 +866,21 @@ async def _run_scorer_for_result( | |
| return self._criterion_error_result( | ||
| base, started_clock, "scorer_raised", f"scorer fn raised: {error}" | ||
| ) | ||
| if isinstance(score_value, bool): | ||
| score: float = 1.0 if score_value else 0.0 | ||
| else: | ||
| maybe_score = numeric_score(score_value) | ||
| if maybe_score is None: | ||
| return self._criterion_error_result( | ||
| base, | ||
| started_clock, | ||
| "invalid_score", | ||
| "scorer fn must return a bool or a finite number, " | ||
| f"got {score_value!r}", | ||
| ) | ||
| score = maybe_score | ||
| if score < 0 or score > 1: | ||
| # A bool is rejected rather than read as 1.0/0.0. numeric_score already | ||
| # excludes it, so the whole return contract is "a finite number in | ||
| # 0-1": a scorer answering a yes/no question returns 1.0 or 0.0 itself. | ||
| # Coercing on the caller's behalf sent two score types to ingest and | ||
| # made the threshold comparison mean different things for binary and | ||
| # graded scorers -- and silently scored `return "high"`-style bugs as a | ||
| # pass, since every non-empty value is truthy. | ||
| score = numeric_score(score_value) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the right shape: one path, and |
||
| if score is None or score < 0 or score > 1: | ||
| return self._criterion_error_result( | ||
| base, | ||
| started_clock, | ||
| "invalid_score", | ||
| f"scorer fn score must be between 0 and 1, got {score_value!r}", | ||
| "scorer fn must return a finite number between 0 and 1, " | ||
| f"got {score_value!r}", | ||
| ) | ||
| completed = datetime.now(UTC) | ||
| return { | ||
|
|
||
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.
Worth narrowing, but this won't catch a bool scorer at type-check time. I ran
mypy --stricton this branch:Scorer(name="a", fn=yes_no)whereyes_noreturnsbool, andfn=lambda row, output: True, both pass. Only a-> strscorer errors.boolis a subclass ofint, andintis accepted wherefloatis expected, and typing has no way to say "float but not bool". So the runtimenumeric_scorecheck is the real guard. Could the PR body and squash message drop the type-check claim?