-
Notifications
You must be signed in to change notification settings - Fork 10
fix(evals): Update Judge Metrics Prompt #1104
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
Changes from all commits
46a3037
6cd310b
5ff0202
194c8f5
6900d8a
5b1074b
28e3b72
b3aea5d
0ab0170
b5b359a
1a75458
c24ce2b
d423928
ff54e8f
215448b
7c91096
28a164a
8a647fc
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 |
|---|---|---|
|
|
@@ -151,7 +151,7 @@ class JudgeMetricSpec: | |
|
|
||
| @dataclass | ||
| class MetricScore: | ||
| """One metric's outcome for a row: score in [0, 1] and its reasoning.""" | ||
| """One metric's outcome for a row: integer score in 0–5 and its reasoning.""" | ||
|
|
||
| score: float | ||
| reasoning: str | ||
|
|
@@ -246,8 +246,11 @@ def _parse_metric_score(key: JudgeMetricEnum, raw: Any) -> MetricScore: | |
| raise ValueError( | ||
| f"metric '{key.value}' score is not a number: {raw.get('score')!r}" | ||
| ) from exc | ||
| if not 0.0 <= score <= 1.0: | ||
| raise ValueError(f"metric '{key.value}' score out of [0, 1]: {score}") | ||
| if score != int(score) or not 0 <= score <= 5: | ||
| raise ValueError( | ||
| f"metric '{key.value}' score must be an integer 0-5: {raw.get('score')!r}" | ||
| ) | ||
| score = int(score) | ||
|
Comment on lines
+249
to
+253
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. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: python - <<'PY'
import json
for literal in ("true", "false", "Infinity", "NaN"):
raw = json.loads(f'{{"score": {literal}}}')["score"]
score = float(raw)
try:
normalized = int(score)
except Exception as exc:
normalized = type(exc).__name__
print(literal, repr(raw), normalized)
PYRepository: ProjectTech4DevAI/kaapi-backend Length of output: 241 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf 'File candidates:\n'
fd -a 'judge\.py$' . | sed 's#^\./##'
printf '\nRelevant file outline:\n'
ast-grep outline backend/app/crud/evaluations/judge.py --view compact || true
printf '\nRelevant source lines 200-270:\n'
sed -n '200,270p' backend/app/crud/evaluations/judge.py | nl -ba -v200
printf '\nSearch for parse_score_usages/ValueError handling near this file:\n'
rg -n "parse_scores|ValueError|score must be an integer|metric '" backend/app/crud/evaluations backend/app -g '*.py' | head -200Repository: ProjectTech4DevAI/kaapi-backend Length of output: 632 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf 'Relevant source lines 200-270:\n'
sed -n '200,270p' backend/app/crud/evaluations/judge.py | awk '{printf "%6d\t%s\n", NR+199, $0}'
printf '\nSearch for parse_scores/usages and related validation:\n'
rg -n "parse_scores|ValueError|score must be an integer|metric '" backend/app/crud/evaluations backend/app -g '*.py' | head -200
printf '\nRelevant tests around score validation:\n'
rg -n "score|ValueError|boolean|Infinity|NaN" backend/app/tests/crud/evaluations/test_judge.py backend/app/tests/crud/evaluations/test_fast_judge.py -g '*.py' | head -200Repository: ProjectTech4DevAI/kaapi-backend Length of output: 48273 🏁 Script executed: #!/bin/bash
set -euo pipefail
python3 - <<'PY'
from typing import Any
from pathlib import Path
src = Path('backend/app/crud/evaluations/judge.py').read_text()
start = src.index('def _parse_metric_score')
end = src.index('\ndef _parse_judge_output', start)
code = src[start:end]
print(code)
print('\nBehavioral probes:')
for literal, raw_value in [('true', True), ('false', False), ('Infinity', 'Infinity'), ('NaN', 'NaN')]:
print(f'>{literal!r}:')
try:
score = float(raw_value)
print(f'float={score!r}')
print(f'isfinite=bool={score != score if score != score else (score == score)}')
if isinstance(score, float):
try:
normalized = int(score)
print(f'int={normalized!r}')
except Exception as exc:
print(f'int_exception={type(exc).__name__}:{exc}')
else:
print('not a float')
except Exception as exc:
print(f'float_exception={type(exc).__name__}:{exc}')
PY
python3 - <<'PY'
from typing import Any
from pathlib import Path
src = Path('backend/app/crud/evaluations/judge.py').read_text()
start = src.index('def _parse_judge_output')
end = src.index('\ndef _judge', end)
code = src[start:end]
print(code)
# Inspect exact exception handling around _parse_judge_output using static source.
lines = code.splitlines()
for i, line in enumerate(lines, 1):
if 'except' in line or '_parse_metric_score' in line or 'except ValueError' in line:
print(f'{i:04d}: {line}')
PYRepository: ProjectTech4DevAI/kaapi-backend Length of output: 1595 Reject boolean and non-finite judge scores before normalization.
Reject booleans, check 🤖 Prompt for AI Agents |
||
|
|
||
| reasoning = str(raw.get("reasoning") or "").strip() | ||
| if not reasoning: | ||
|
|
||
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: ProjectTech4DevAI/kaapi-backend
Length of output: 50387
🏁 Script executed:
Repository: ProjectTech4DevAI/kaapi-backend
Length of output: 2816
Use an integer contract for judge scores.
MetricScore.scoreis parsed as an integer inbackend/app/crud/evaluations/judge.py#L237, but the dataclass still annotates it asfloat. Update that field tointand change_both_metrics_responsescore tuples inbackend/app/tests/crud/evaluations/test_fast_judge.py#L172-173fromtuple[float, str]totuple[int, str]so the contracts stay aligned.📍 Affects 2 files
backend/app/crud/evaluations/judge.py#L154-L154(this comment)backend/app/tests/crud/evaluations/test_fast_judge.py#L172-L173🤖 Prompt for AI Agents
Source: Coding guidelines