Skip to content

fix(589): score the reply get_comparison_details already fetched - #652

Merged
digalaviz merged 2 commits into
awslabs:devfrom
harrycav:fix/589-single-llm-call
Dec 1, 2026
Merged

digalaviz merged 2 commits into
awslabs:devfrom
harrycav:fix/589-single-llm-call

Conversation

@harrycav

Copy link
Copy Markdown
Contributor

Fixes #589.

get_comparison_details now makes one model call and scores that reply, so the shown llm_response is the scored one. The verdict logic is shared with compare() (_score_reply). A None/NaN input no longer calls the model (prompt and llm_response are None); the score is unchanged.

Full suite passes on the merge with current dev; 8 tests in test_llm.py fail on dev.

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.
@github-actions

Copy link
Copy Markdown

Security Scan Results

ASH Security Scan Report

  • Report generated: 2026-11-27T20:29:43+00:00
  • Time since scan: 3 minutes

Scan Metadata

  • Project: ASH
  • Scan executed: 2026-11-27T20:25:58+00:00
  • ASH version: 3.1.2

Summary

Scanner Results

The table below shows findings by scanner, with status based on severity thresholds and dependencies:

  • Severity levels:
    • Suppressed (S): Findings that have been explicitly suppressed and don't affect scanner status
    • Critical (C): Highest severity findings that require immediate attention
    • High (H): Serious findings that should be addressed soon
    • Medium (M): Moderate risk findings
    • Low (L): Lower risk findings
    • Info (I): Informational findings with minimal risk
  • Duration (Time): Time taken by the scanner to complete its execution
  • Actionable: Number of findings at or above the threshold severity level that require attention
  • Result:
    • PASSED = No findings at or above threshold
    • FAILED = Findings at or above threshold
    • MISSING = Required dependencies not available
    • SKIPPED = Scanner explicitly disabled
    • ERROR = Scanner execution error
  • Threshold: The minimum severity level that will cause a scanner to fail
    • Thresholds: ALL, LOW, MEDIUM, HIGH, CRITICAL
    • Source: Values in parentheses indicate where the threshold is set:
      • global (global_settings section in the ASH_CONFIG used)
      • config (scanner config section in the ASH_CONFIG used)
      • scanner (default configuration in the plugin, if explicitly set)
  • Statistics calculation:
    • All statistics are calculated from the final aggregated SARIF report
    • Suppressed findings are counted separately and do not contribute to actionable findings
    • Scanner status is determined by comparing actionable findings to the threshold
Scanner Suppressed Critical High Medium Low Info Actionable Result Threshold
bandit 0 0 0 0 7463 0 0 PASSED MEDIUM (global)
cdk-nag 0 0 0 0 0 0 0 PASSED MEDIUM (global)
cfn-nag 0 0 0 0 0 0 0 MISSING MEDIUM (global)
checkov 0 0 0 0 0 0 0 PASSED MEDIUM (global)
detect-secrets 0 0 0 0 0 0 0 PASSED MEDIUM (global)
grype 0 0 0 0 0 0 0 MISSING MEDIUM (global)
npm-audit 0 0 0 0 0 0 0 PASSED MEDIUM (global)
opengrep 0 0 0 0 0 0 0 MISSING MEDIUM (global)
semgrep 3 0 0 0 0 0 0 PASSED MEDIUM (global)
syft 0 0 0 0 0 0 0 MISSING MEDIUM (global)

Report generated by Automated Security Helper (ASH) at 2026-11-27T20:29:44+00:00

@vawsgit vawsgit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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-tree merges 37bc6301 (#645) and 328332d0 cleanly. The two PRs change different methods: #645 changes _invoke_agent, and this PR changes _compare and get_comparison_details, which call it. On the merged tree, a reply with a reasoningContent block, 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: dev 6642 passed, 0 failed. 328332d0 6650 passed, 0 failed.
  • Fixes #589 is right: one call, the shown reply is scored, and the test asserts call_count == 1 with two different replies.

@mangeshraut712 mangeshraut712 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 digalaviz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@digalaviz
digalaviz merged commit b9bbe04 into awslabs:dev Dec 1, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LLMComparator.get_comparison_details calls the model twice, so the shown reply can differ from the scored one

4 participants