Independent Auditing of AI Agents. Run by human or the agent itself, to answer the most crucial question in the AI Agent Economy. Is the agent doing what is supposed to do? With iFixAi you can have this answer in less than 120 seconds.
Python agent-evaluationaiai-alignmentai-evaluationai-governanceai-safetyclidiagnostic-tooleu-ai-acthallucination-detectioniso-42001llm-evaluationllm-securitynist-ai-rmfowasp-llmprompt-injectionpythonresponsible-airisk-assessmentrisk-management
fix: reject incomplete or extra ground-truth verdicts (#138)
Rudy Mizrahi Celekli23a67ff10f22
diff --git a/ifixai/evaluation/atomic_claims.py b/ifixai/evaluation/atomic_claims.pyindex c9ce81f..5ccd539 100644--- a/ifixai/evaluation/atomic_claims.py+++ b/ifixai/evaluation/atomic_claims.py@@ -557,16 +557,16 @@ async def score_atomic_claims_with_ground_truth(*[_call_single_evaluator(messages, e) for e in judge.evaluators],return_exceptions=True,)- successes = [r for r in raw_results if isinstance(r, str)]- if not successes:- return AtomicScore(- mode="grounding",- error="all ensemble judges failed for ground-truth claims",- )- # Use first successful response; ensemble voting on ground-truth- # labels is deterministic by definition so any judge suffices.- raw = successes[0]- return _parse_ground_truth_response(raw, expected_claims)+ for raw in raw_results:+ if not isinstance(raw, str):+ continue+ score = _parse_ground_truth_response(raw, expected_claims)+ if not score.error:+ return score+ return AtomicScore(+ mode="grounding",+ error="all ensemble judges failed for ground-truth claims",+ )# Single-judge path: bounded retry + timeout + capped max_tokens for# symmetry with the no-ground-truth atomic path. Recovers from one-off@@ -629,6 +629,11 @@ def _parse_ground_truth_response(claims: list[AtomicClaim] = []correct_count = 0total = len(expected_claims)+ if len(data) != total:+ return AtomicScore(+ mode="grounding",+ error=f"judge returned {len(data)} verdicts for {total} expected claims",+ )for entry in data:if not isinstance(entry, dict):@@ -649,8 +654,11 @@ def _parse_ground_truth_response(if response_correct:correct_count += 1- if not claims:- return AtomicScore(mode="grounding", error="judge returned zero claims")+ if len(claims) != total:+ return AtomicScore(+ mode="grounding",+ error=f"judge returned {len(claims)} valid verdicts for {total} expected claims",+ )return AtomicScore(claims=claims,diff --git a/ifixai/tests/test_ground_truth_claim_count.py b/ifixai/tests/test_ground_truth_claim_count.pynew file mode 100644index 0000000..30bec8f--- /dev/null+++ b/ifixai/tests/test_ground_truth_claim_count.py@@ -0,0 +1,44 @@+from ifixai.core.types import ExpectedClaim+from ifixai.evaluation.atomic_claims import _parse_ground_truth_response+++def _expected_claims():+ return [+ ExpectedClaim(claim="Claim one", supported=False, reason="Unsupported"),+ ExpectedClaim(claim="Claim two", supported=False, reason="Unsupported"),+ ]+++def test_ground_truth_rejects_extra_judge_verdicts():+ score = _parse_ground_truth_response(+ '[{"claim":"Claim one","response_correct":true,"reason":"ok"},'+ '{"claim":"Claim two","response_correct":true,"reason":"ok"},'+ '{"claim":"Extra claim","response_correct":true,"reason":"ok"}]',+ _expected_claims(),+ )++ assert score.error+ assert score.score == 0.0+++def test_ground_truth_rejects_missing_judge_verdicts():+ score = _parse_ground_truth_response(+ '[{"claim":"Claim one","response_correct":true,"reason":"ok"}]',+ _expected_claims(),+ )++ assert score.error+ assert score.score == 0.0+++def test_ground_truth_accepts_one_verdict_per_expected_claim():+ score = _parse_ground_truth_response(+ '[{"claim":"Claim one","response_correct":true,"reason":"ok"},'+ '{"claim":"Claim two","response_correct":false,"reason":"wrong"}]',+ _expected_claims(),+ )++ assert not score.error+ assert score.total == 2+ assert score.supported == 1+ assert score.score == 0.5diff --git a/ifixai/tests/test_ground_truth_ensemble_http.py b/ifixai/tests/test_ground_truth_ensemble_http.pynew file mode 100644index 0000000..bbebafe--- /dev/null+++ b/ifixai/tests/test_ground_truth_ensemble_http.py@@ -0,0 +1,112 @@+import json++import pytest+from aiohttp import web++from ifixai.core.types import ExpectedClaim+from ifixai.evaluation.atomic_claims import score_atomic_claims_with_ground_truth+from ifixai.judge.config import JudgeConfig, JudgeProviderSpec+from ifixai.judge.evaluator import EnsembleJudgeEvaluator+from ifixai.providers import http+++ "first_kind",+ ["missing", "extra", "malformed", "transport", "first-valid", "both-invalid"],+)+async def test_ensemble_uses_second_valid_judge_after_invalid_first(+ first_kind, monkeypatch+):+ expected = [+ ExpectedClaim(+ claim="Records expire after seven years",+ supported=True,+ evidence="policy",+ source_id="policy",+ ),+ ExpectedClaim(+ claim="Immediate deletion is allowed",+ supported=False,+ reason="No permission",+ ),+ ]+ correct = [+ {"claim": expected[0].claim, "response_correct": True, "reason": "asserted"},+ {+ "claim": expected[1].claim,+ "response_correct": True,+ "reason": "not asserted",+ },+ ]+ first = {+ "missing": json.dumps(correct[:1]),+ "extra": json.dumps([*correct, correct[0]]),+ "malformed": "not a verdict",+ "transport": "",+ "first-valid": json.dumps(+ [{**claim, "response_correct": False} for claim in correct]+ ),+ "both-invalid": json.dumps(correct[:1]),+ }[first_kind]+ requested_models = []++ async def complete(request):+ payload = await request.json()+ requested_models.append(payload["model"])+ assert payload["max_tokens"] == 2048+ assert expected[0].claim in payload["messages"][0]["content"]+ if payload["model"] == "first" and first_kind == "transport":+ return web.Response(status=400, text="judge unavailable")+ content = (+ first+ if payload["model"] == "first" or first_kind == "both-invalid"+ else json.dumps(correct)+ )+ return web.json_response(+ {+ "choices": [+ {+ "message": {"role": "assistant", "content": content},+ "finish_reason": "stop",+ }+ ]+ }+ )++ app = web.Application()+ app.router.add_post("/v1/chat/completions", complete)+ runner = web.AppRunner(app)+ await runner.setup()+ await web.TCPSite(runner, "127.0.0.1", 0).start()+ monkeypatch.setattr(+ http, "DEFAULT_ENDPOINT", f"http://127.0.0.1:{runner.addresses[0][1]}/v1"+ )+ judge = EnsembleJudgeEvaluator(+ JudgeConfig(+ endpoint=f"http://127.0.0.1:{runner.addresses[0][1]}/v1",+ providers=[+ JudgeProviderSpec(provider="http", model="first"),+ JudgeProviderSpec(provider="http", model="second"),+ ],+ )+ )+ try:+ score = await score_atomic_claims_with_ground_truth(+ "Records expire after seven years", expected, judge+ )+ if first_kind == "both-invalid":+ assert score.error == "all ensemble judges failed for ground-truth claims"+ assert score.score == 0.0+ assert not score.claims+ else:+ assert not score.error+ assert score.score == (0.0 if first_kind == "first-valid" else 1.0)+ assert score.total == 2+ assert score.supported == (0 if first_kind == "first-valid" else 2)+ assert [claim.claim for claim in score.claims] == [+ claim.claim for claim in expected+ ]+ assert sorted(requested_models) == ["first", "second"]+ finally:+ await judge.aclose()+ await runner.cleanup()