diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a656c5f2..a1768aa68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,6 +102,10 @@ All notable changes to SkillEvaluator are documented in this file. records its scoring policy. Reports separately expose measured token and agent execution-time differences with complete matching-arm coverage, while efficiency continues to measure routing and productive tool use. +- Derive accuracy scores from complete criterion verdicts in both judge + runtimes (passing applicable criteria divided by applicable criteria), so an + inconsistent model-supplied total cannot distort Skill Lift. Correct the + Harbor prompt example to score five passing criteria as 1.0. - Include schema-valid ATIF message content parts in final answers, conversation summaries, and judge evidence references in the host and Harbor verifier. Image and audio parts use markers without exposing their source paths. diff --git a/docs/tier3-live-evaluation.mdx b/docs/tier3-live-evaluation.mdx index 64486c6be..2c78c2bf3 100644 --- a/docs/tier3-live-evaluation.mdx +++ b/docs/tier3-live-evaluation.mdx @@ -552,11 +552,14 @@ grades each trial after the agent finishes. `security`, `skill_execution`, and `goal_accuracy`, and `behavior_check` are LLM judges that call the configured evaluator provider. `custom_only` runs none of them. -When `should_trigger` is false or no `expected_skill` is declared, accuracy -excludes `SKILL_IDENTIFIED` and calculates the score from the other four -criterion verdicts. The reward details record the excluded criterion and -`applicable-accuracy-criteria/v1` scoring policy. Missing criterion evidence is -an error. Positive cases retain their existing scoring contract. +Accuracy is calculated from the judge's criterion verdicts, not its numeric +total: passing applicable criteria divided by applicable criteria. Positive +cases score all five criteria; a positive-case reply with no criteria falls +back to the judge's numeric score. When `should_trigger` is false or no +`expected_skill` is declared, accuracy excludes `SKILL_IDENTIFIED` from both +counts and scores the other four criterion verdicts. The reward details record +the excluded criterion and `applicable-accuracy-criteria/v1` scoring policy. +Missing criterion evidence is an error for these cases. ### The graded trajectory diff --git a/src/skillevaluator/tier3/eval_core/llm_judge.py b/src/skillevaluator/tier3/eval_core/llm_judge.py index d9317e944..2841ecd1c 100644 --- a/src/skillevaluator/tier3/eval_core/llm_judge.py +++ b/src/skillevaluator/tier3/eval_core/llm_judge.py @@ -809,14 +809,16 @@ def validate_payload(parsed: Any) -> str | None: criteria = parsed.get("criteria") criteria_valid = _valid_accuracy_criteria(criteria) - score = _finite_score(parsed.get("score")) - if not skill_identification_applicable: - assert criteria_valid - score = sum(value is True for key, value in criteria.items() if key != "SKILL_IDENTIFIED") / 4.0 - elif score is None: - assert criteria_valid - yes_count = sum(1 for v in criteria.values() if v is True) - score = yes_count / 5.0 + if criteria_valid: + # Score only applicable verdicts; excluded criteria leave both numerator and denominator. + excluded = set() if skill_identification_applicable else {"SKILL_IDENTIFIED"} + applicable = [verdict for name, verdict in criteria.items() if name not in excluded] + score = sum(verdict is True for verdict in applicable) / len(applicable) + else: + # Legacy score-only payloads; validate_payload rejects them when a criterion is excluded. + assert skill_identification_applicable + score = _finite_score(parsed.get("score")) + assert score is not None result = { "score": round(score, 4), diff --git a/src/skillevaluator/tier3/harbor/templates/eval.py b/src/skillevaluator/tier3/harbor/templates/eval.py index ba22e0798..2c3087f42 100644 --- a/src/skillevaluator/tier3/harbor/templates/eval.py +++ b/src/skillevaluator/tier3/harbor/templates/eval.py @@ -8250,7 +8250,7 @@ def judge_accuracy(question, ground_truth, agent_text, *, skill_identification_a Be lenient on exact wording but strict on factual correctness. Respond with ONLY a JSON object: -{{"criteria": {{"SKILL_IDENTIFIED": true, "ACTION_CORRECT": true, "FACTUALLY_ACCURATE": true, "TASK_ADDRESSED": true, "ACTIONABLE": true}}, "score": 0.8, "reason": "brief summary"}} +{{"criteria": {{"SKILL_IDENTIFIED": true, "ACTION_CORRECT": true, "FACTUALLY_ACCURATE": true, "TASK_ADDRESSED": true, "ACTIONABLE": true}}, "score": 1.0, "reason": "brief summary"}} USER QUESTION: {question} @@ -8266,9 +8266,7 @@ def judge_accuracy(question, ground_truth, agent_text, *, skill_identification_a "1. SKILL_IDENTIFIED: Does the response reference or use the correct skill for the task?", "1. SKILL_IDENTIFIED: Inapplicable: no skill is expected. Set false; exclude it from the score.", ).replace("Compute score = count(true) / 5.", "Compute score = count(true among the other four criteria) / 4.") - prompt = prompt.replace('"SKILL_IDENTIFIED": true', '"SKILL_IDENTIFIED": false').replace( - '"score": 0.8', '"score": 1.0' - ) + prompt = prompt.replace('"SKILL_IDENTIFIED": true', '"SKILL_IDENTIFIED": false') # Adjust the rubric before interpolation so task/evidence text stays intact. prompt = prompt.format(question=question, ground_truth=ground_truth, agent_text=agent_text) @@ -8293,13 +8291,16 @@ def validate_payload(parsed): criteria = parsed.get("criteria") criteria_valid = _valid_accuracy_criteria(criteria) - score = _finite_score(parsed.get("score")) - if not skill_identification_applicable: - assert criteria_valid - score = sum(value is True for key, value in criteria.items() if key != "SKILL_IDENTIFIED") / 4.0 - elif score is None: - assert criteria_valid - score = sum(1 for v in criteria.values() if v is True) / 5.0 + if criteria_valid: + # Score only applicable verdicts; excluded criteria leave both numerator and denominator. + excluded = set() if skill_identification_applicable else {"SKILL_IDENTIFIED"} + applicable = [verdict for name, verdict in criteria.items() if name not in excluded] + score = sum(verdict is True for verdict in applicable) / len(applicable) + else: + # Legacy score-only payloads; validate_payload rejects them when a criterion is excluded. + assert skill_identification_applicable + score = _finite_score(parsed.get("score")) + assert score is not None result = { "score": round(score, 4), "reason": _bounded_judge_text(parsed.get("reason", "")), diff --git a/tests/test_accuracy_arithmetic.py b/tests/test_accuracy_arithmetic.py new file mode 100644 index 000000000..76f26f8b2 --- /dev/null +++ b/tests/test_accuracy_arithmetic.py @@ -0,0 +1,98 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +"""Accuracy scores must implement the applicable-criterion rubric in both runtimes.""" + +from __future__ import annotations + +import json +from pathlib import Path + +import pytest +from tests.conftest import load_harbor_eval_template + +from skillevaluator.tier3.eval_core import llm_judge +from skillevaluator.tier3.harbor.collector import _compute_lift + + +@pytest.fixture(params=["host", "harbor"]) +def accuracy_judge(request: pytest.FixtureRequest): + if request.param == "host": + return llm_judge + return load_harbor_eval_template("accuracy_arithmetic_template") + + +def _criteria(passed: int) -> dict[str, bool]: + return {key: index < passed for index, key in enumerate(sorted(llm_judge._ACCURACY_CRITERIA_KEYS))} + + +@pytest.mark.parametrize("passed", range(6)) +def test_accuracy_derives_score_from_complete_criteria(monkeypatch, accuracy_judge, passed): + payload = {"criteria": _criteria(passed), "score": 1 - passed / 5, "reason": "rubric verdicts"} + monkeypatch.setattr(accuracy_judge, "call_public_llm", lambda *_args, **_kwargs: (json.dumps(payload), None)) + + result = accuracy_judge.judge_accuracy("Summarize the CSV", "The total is 120", "The total is 120") + + assert result["score"] == pytest.approx(passed / 5) + assert result["criteria"] == payload["criteria"] + assert "error" not in result + + +@pytest.mark.parametrize("skill_verdict", [True, False]) +@pytest.mark.parametrize("passed", range(5)) +def test_negative_accuracy_scores_only_applicable_criteria(monkeypatch, accuracy_judge, passed, skill_verdict): + # Negative cases drop SKILL_IDENTIFIED from numerator and denominator; the model total stays ignored. + applicable = sorted(llm_judge._ACCURACY_CRITERIA_KEYS - {"SKILL_IDENTIFIED"}) + criteria = {key: index < passed for index, key in enumerate(applicable)} + criteria["SKILL_IDENTIFIED"] = skill_verdict + payload = {"criteria": criteria, "score": 0.1, "reason": "declined correctly"} + monkeypatch.setattr(accuracy_judge, "call_public_llm", lambda *_args, **_kwargs: (json.dumps(payload), None)) + + result = accuracy_judge.judge_accuracy("question", "reference", "answer", skill_identification_applicable=False) + + assert result["score"] == pytest.approx(passed / 4) + assert result["criteria"] == criteria + assert result["excluded_criteria"] == ["SKILL_IDENTIFIED"] + assert result["scoring_policy"] == "applicable-accuracy-criteria/v1" + + +def test_tier3_docs_describe_criterion_derived_accuracy(): + docs = (Path(__file__).resolve().parents[1] / "docs" / "tier3-live-evaluation.mdx").read_text(encoding="utf-8") + normalized = " ".join(docs.split()) + + assert "passing applicable criteria divided by applicable criteria" in normalized + assert "falls back to the judge's numeric score" in normalized + assert "existing scoring contract" not in normalized + + +@pytest.mark.parametrize( + "payload, expected", + [ + ({"criteria": _criteria(3), "score": 0.6}, 0.6), + ({"criteria": _criteria(3)}, 0.6), + ({"score": 0.6}, 0.6), + ], +) +def test_accuracy_preserves_consistent_and_legacy_payloads(monkeypatch, accuracy_judge, payload, expected): + monkeypatch.setattr(accuracy_judge, "call_public_llm", lambda *_args, **_kwargs: (json.dumps(payload), None)) + assert accuracy_judge.judge_accuracy("question", "reference", "answer")["score"] == expected + + +def test_accuracy_example_does_not_reverse_skill_lift(monkeypatch, accuracy_judge): + # The shipped Harbor prompt used all five true with a numeric score of 0.8. + payloads = iter( + [ + {"criteria": _criteria(5), "score": 0.8}, + {"criteria": _criteria(5), "score": 0.8}, + {"criteria": _criteria(4), "score": 0.8}, + {"criteria": _criteria(5), "score": 1.0}, + ] + ) + monkeypatch.setattr(accuracy_judge, "call_public_llm", lambda *_args, **_kwargs: (json.dumps(next(payloads)), None)) + scores = [accuracy_judge.judge_accuracy("question", "reference", "answer")["score"] for _ in range(4)] + lift = _compute_lift({"accuracy": sum(scores[:2]) / 2}, {"accuracy": sum(scores[2:]) / 2}) + + assert lift["accuracy"]["with_skill"] == 1.0 + assert lift["accuracy"]["without_skill"] == 0.9 + assert lift["accuracy"]["delta"] == 0.1 + assert lift["accuracy"]["direction"] == "up"