Repository navigation
fix(589): score the reply get_comparison_details already fetched - #652
Conversation
get_comparison_details called the model twice: once for llm_response and again through compare() for comparison_result, so the score could come from a different reply than the one shown. It now scores the reply it fetched, through the same _score_reply helper _compare uses, and skips the model for None/NaN inputs, which the None policy scores without it.
Security Scan ResultsASH Security Scan Report
Scan Metadata
SummaryScanner ResultsThe table below shows findings by scanner, with status based on severity thresholds and dependencies:
Report generated by Automated Security Helper (ASH) at 2026-11-27T20:29:44+00:00 |
vawsgit
left a comment
There was a problem hiding this comment.
✅ LGTM!
Measured from scratch worktrees with PYTHONPATH pinned to each tree's src; dev is 13a21ba0, the base of this PR. The stub replaces stickler.comparators.llm.Agent with a class that counts calls and returns set replies.
| Check | dev |
328332d0 |
|---|---|---|
Model calls per get_comparison_details |
2 | 1 |
Issue example (replies "true", then "True, they are equivalent.") |
shows 'true', scores 0.0 |
shows 'true', scores 1.0 |
Score equals compare() for the same reply (10 replies: true, false, TRUE., **true**, `false`, 'True', maybe, True, they are equivalent., empty, Not true) |
10 of 10 | 10 of 10 |
| Warning for an unreadable reply points at | llm.py |
the caller's file |
None/NaN input: model calls |
1 | 0 (prompt and llm_response are None) |
None/NaN input: score |
same as compare() |
same as compare() |
| Agent raises | error dict, 1 call |
error dict, 1 call |
- #645: no conflict.
git merge-treemerges37bc6301(#645) and328332d0cleanly. The two PRs change different methods: #645 changes_invoke_agent, and this PR changes_compareandget_comparison_details, which call it. On the merged tree, a reply with areasoningContentblock, then"true", makes 1 model call and scores 1.0. On #645 alone it makes 2 calls. A reply with no text block gives{'error': 'LLM reply has no text content block', 'comparison_result': False}, the same as on #645 alone. Full suite on the merge: 6651 passed, 0 failed. - Full suite:
dev6642 passed, 0 failed.328332d06650 passed, 0 failed. Fixes #589is right: one call, the shown reply is scored, and the test assertscall_count == 1with two different replies.
mangeshraut712
left a comment
There was a problem hiding this comment.
Tested the PR head (328332d0b) in a clean worktree.
Result: 73/73 pass in test_llm.py. Teeth confirmed: with main's llm.py and the PR's tests, exactly 8 fail — matching the description's count. The failing set is the behavioral one: scores_the_reply_it_shows[true-false-1.0], [false-true-0.0] (the cases where a second call would show one reply and score another), uses_strict_verdict, and all four missing_values_follow_none_policy params.
I also drove the comparator directly with a mock agent to check the three things the PR claims:
One model call, and the shown reply is the scored one.
[calls for get_comparison_details] agent.call_count=1
[shown='false' scored=0.0] calls=1 # reply sequence ["false","true"]: first answer wins, shown == scored
compare() and get_comparison_details() agree on every reply shape — true, false, TRUE, True., maybe all give the same score on both paths, since both now route through _score_reply.
None / NaN skip the model entirely and follow the shared policy.
(None, 'b') -> result=0.0 prompt=None resp=None calls=0
(None, None) -> result=1.0 prompt=None resp=None calls=0
(nan, 'b') -> result=0.0 prompt=None resp=None calls=0
('a', nan) -> result=0.0 prompt=None resp=None calls=0
The _is_missing import is the same predicate BaseComparator.compare uses (line 62 of base.py), so the two paths can't drift.
stacklevel is right on both paths. With warnings.record=True, the UserWarning for an unreadable reply is attributed to the caller's own line — test_probe_652.py:69 for a direct compare() (stacklevel 4) and :78 for get_comparison_details() (stacklevel 3). The bump from 3→4 in compare() correctly accounts for the new _score_reply frame, and the inline comments tracing the frame chain are helpful.
The error path is unchanged: an agent exception still returns {"error": ..., "comparison_result": False}.
One pre-existing wart, not introduced here — flagging only because this PR touches the return shape. The success path returns comparison_result as a float (1.0/0.0) and the error path as the bool False. Since isinstance(False, int) and False == 0.0, it mostly works, but a consumer doing type(d["comparison_result"]) is float or serialising to a strict schema would see the difference. If you'd rather not widen this PR, a follow-up to make it 0.0 (or a dedicated key) would be a one-liner.
The docstring update (return types str or None, the "model is called once" sentence) is accurate, and the docs page change matches. LGTM — this is the right fix for #589.
digalaviz
left a comment
There was a problem hiding this comment.
Approving. I checked 328332d merged with dev 33ed6c3e: full suite 7126 passed, 13 skipped, 1 xfailed, ruff check passes, no conflicts. With a stub agent that replies "true" and then "True, they are equivalent.", get_comparison_details now makes one call and scores the reply it shows (1.0), where dev made two. A None or NaN input skips the model and scores the same as before, since the gate is the same _is_missing that BaseComparator.compare uses. An unparsable reply now warns at the caller for both compare() and get_comparison_details.
Fixes #589.
get_comparison_detailsnow makes one model call and scores that reply, so the shownllm_responseis the scored one. The verdict logic is shared withcompare()(_score_reply). A None/NaN input no longer calls the model (promptandllm_responseareNone); the score is unchanged.Full suite passes on the merge with current
dev; 8 tests intest_llm.pyfail ondev.