Repository navigation
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
0bc9544
57ee142
e6e9e82
8608c38
bc596c0
52f69be
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 |
|---|---|---|
|
|
@@ -867,6 +867,7 @@ async def _run_scorer_for_result( | |
| self, | ||
| row: Mapping[str, Any], | ||
| scorer: Scorer, | ||
| warned_scorers: set[str], | ||
| ) -> dict[str, Any]: | ||
| started = datetime.now(UTC) | ||
| started_clock = time.perf_counter() | ||
|
|
@@ -898,25 +899,26 @@ 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 {_describe_value(score_value)}", | ||
| # 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) | ||
|
jeffdupont marked this conversation as resolved.
|
||
| if score is None or score < 0 or score > 1: | ||
| message = ( | ||
| "scorer fn must return a finite number between 0 and 1, " | ||
| f"got {_describe_value(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. 🔴 Invalid scorer values abort evaluation runs When a scorer returns a mapping with tuple keys, Learn moreThe scorer's return value is supplied by customer code. An invalid return must become a per-criterion ERROR, leaving the run free to emit events for all rows. Here Example: A scorer returns Recommended fix: Make Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| ) | ||
| if scorer.name not in warned_scorers: | ||
| warned_scorers.add(scorer.name) | ||
| logger.warning( | ||
| "scorer %r returned an invalid score: %s", scorer.name, message | ||
| ) | ||
| score = maybe_score | ||
| if 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 {_describe_value(score_value)}", | ||
| base, started_clock, "invalid_score", message | ||
| ) | ||
| completed = datetime.now(UTC) | ||
| return { | ||
|
|
@@ -1030,14 +1032,17 @@ async def _run_criteria_for_results( | |
| ) -> list[dict[str, Any]]: | ||
| """Run every (row, criterion) pair, bounded by the run's concurrency.""" | ||
| controller = ConcurrencyController(concurrency) | ||
| warned_scorers: set[str] = set() | ||
|
|
||
| async def run_one( | ||
| row: Mapping[str, Any], criterion: Criterion | ||
| ) -> dict[str, Any]: | ||
| await controller.acquire() | ||
| try: | ||
| if isinstance(criterion, Scorer): | ||
| return await self._run_scorer_for_result(row, criterion) | ||
| return await self._run_scorer_for_result( | ||
| row, criterion, warned_scorers | ||
| ) | ||
| return await self._run_ld_judge_for_result( | ||
| row, | ||
| criterion, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.