Skip to content

Commit fcc5338

Browse files
Agent study: read the openevals score as structured output would
The command line has no structured output, so a judge reply can break its JSON with an unescaped quote or send the score as a string. The pilot had three such replies out of 375; openevals itself cannot get them.
1 parent 0c7ad65 commit fcc5338

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

‎study/agents/run_judges.py‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,26 @@ def _json_object(text: str) -> dict[str, Any]:
320320

321321

322322
def openevals_score(text: str) -> bool:
323-
score = _json_object(text).get("score")
324-
if not isinstance(score, bool):
325-
raise ValueError(f"no boolean 'score' in the judge's reply: {text[:120]!r}")
326-
return score
323+
"""The boolean score of the reply.
324+
325+
openevals gets it through structured output, so its judge cannot send
326+
malformed JSON. Here the schema is only asked for in text, and a reply
327+
can break the JSON with an unescaped quote in its reasoning or send the
328+
score as a string. Both are read as structured output would have taken
329+
them: the last "score" field, true or false.
330+
"""
331+
try:
332+
score = _json_object(text).get("score")
333+
except ValueError:
334+
score = None
335+
if isinstance(score, str) and score.strip().lower() in ("true", "false"):
336+
score = score.strip().lower() == "true"
337+
if isinstance(score, bool):
338+
return score
339+
found = re.findall(r'"score"\s*:\s*"?(true|false)\b', text, re.IGNORECASE)
340+
if found:
341+
return found[-1].lower() == "true"
342+
raise ValueError(f"no boolean 'score' in the judge's reply: {text[:120]!r}")
327343

328344

329345
def deepeval_verdict(text: str) -> float:

‎tests/test_study_agents.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,16 @@ def test_the_tools_called_are_printed_as_deepeval_prints_them():
6868
[
6969
('{"reasoning": "Fine. Thus, the score should be: true.", "score": true}', True),
7070
('Here it is:\n{"reasoning": "No refund call.", "score": false}', False),
71+
# What structured output would have kept from replies sent as text.
72+
('{"reasoning": "It says "done" but made no call.", "score": false}', False),
73+
('{"reasoning": "Fine.", "score": "true"}', True),
7174
],
7275
)
7376
def test_the_openevals_score_is_read_from_the_json(reply, passed):
7477
assert j.openevals_score(reply) is passed
7578

7679

77-
@pytest.mark.parametrize("reply", ["true", '{"score": "true"}', '{"reasoning": "x"}'])
80+
@pytest.mark.parametrize("reply", ["true", '{"score": "yes"}', '{"reasoning": "x"}'])
7881
def test_a_reply_without_a_boolean_score_is_no_verdict(reply):
7982
with pytest.raises(ValueError):
8083
j.openevals_score(reply)

0 commit comments

Comments
 (0)