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(evaluation): keep budget-skipped probes unscored (#169)
Rudy Mizrahi Celekli33369e1de542
diff --git a/ifixai/cli/run.py b/ifixai/cli/run.pyindex 5834ad0..aae06e2 100644--- a/ifixai/cli/run.py+++ b/ifixai/cli/run.py@@ -1840,7 +1840,8 @@ def run(result.validation_warnings.append("run_invalid: measurement failure — "f"errored={health.errored}/{health.n_inspections} inspections, "- f"unreachable={health.unreachable}/{health.total} model calls, "+ f"unreachable={health.unreachable}/{health.attempted_probes} attempted probes, "+ f"budget_skipped={health.budget_skipped}, "f"judge_broke={health.judge_broke}, scorable={health.scorable}. ""Ignore the grade.")diff --git a/ifixai/core/types.py b/ifixai/core/types.pyindex 2a7c290..933c779 100644--- a/ifixai/core/types.py+++ b/ifixai/core/types.py@@ -201,6 +201,7 @@ class JudgeErrorKind(str, Enum):COMMUNICATION = "communication"EXTRACTION = "extraction"CONTRACT = "contract"+ BUDGET = "budget"class EvaluationMode(str, Enum):diff --git a/ifixai/evaluation/pipeline.py b/ifixai/evaluation/pipeline.pyindex fc5a596..e08008f 100644--- a/ifixai/evaluation/pipeline.py+++ b/ifixai/evaluation/pipeline.py@@ -218,6 +218,7 @@ class EvaluationPipeline:passed=False,evaluation_result="inconclusive: judge budget exhausted",evaluation_method=EvaluationMethod.JUDGE,+ extraction_error=JudgeErrorKind.BUDGET,)diff --git a/ifixai/reporting/health.py b/ifixai/reporting/health.pyindex 7762403..e35e091 100644--- a/ifixai/reporting/health.py+++ b/ifixai/reporting/health.py@@ -21,6 +21,11 @@ class _RunHealth(NamedTuple):scorable: int # produced a graded result (no extraction_error)unreachable: int # a model call failed to communicate (agent OR judge)judge_broke: int # the judge replied but the verdict was unusable+ budget_skipped: int = 0 # no judge call was made after the run budget ran out++ @property+ def attempted_probes(self) -> int:+ return self.total - self.budget_skipped@propertydef invalid(self) -> bool:@@ -36,7 +41,7 @@ class _RunHealth(NamedTuple):return self.n_inspections > 0if self.scorable == 0:return True # every probe was unscorable- return self.unreachable / self.total >= 0.5+ return self.attempted_probes > 0 and self.unreachable / self.attempted_probes >= 0.5@propertydef low_confidence(self) -> bool:@@ -61,8 +66,9 @@ def run_health(result: TestRunResult) -> _RunHealth:COMMUNICATION is a failed model call on either seam (agent under test orjudge); CONTRACT/EXTRACTION mean the judge answered but the verdict was- unusable — unambiguously a grader-health problem."""- errored = total = scorable = unreachable = judge_broke = 0+ unusable — unambiguously a grader-health problem. BUDGET means no judge+ call was made, so it is neither a transport nor a verdict failure."""+ errored = total = scorable = unreachable = judge_broke = budget_skipped = 0for br in result.test_results:if br.status == TestStatus.ERROR:errored += 1@@ -77,9 +83,11 @@ def run_health(result: TestRunResult) -> _RunHealth:unreachable += 1elif kind in (JudgeErrorKind.CONTRACT, JudgeErrorKind.EXTRACTION):judge_broke += 1+ elif kind == JudgeErrorKind.BUDGET:+ budget_skipped += 1else:unreachable += 1- return _RunHealth(len(result.test_results), errored, total, scorable, unreachable, judge_broke)+ return _RunHealth(len(result.test_results), errored, total, scorable, unreachable, judge_broke, budget_skipped)def measurement_failure_banner(health: _RunHealth) -> str | None:@@ -94,6 +102,12 @@ def measurement_failure_banner(health: _RunHealth) -> str | None:f"all {health.n_inspections} inspection(s) ran but produced no gradeable ""evidence. Check the model id / key / endpoint and re-run.")+ elif health.budget_skipped == health.total and not health.errored:+ cause = (+ f"all {health.budget_skipped} probes were skipped because the judge "+ "budget was exhausted; no judge call was made for those probes. "+ "Increase the judge budget or select fewer inspections and re-run."+ )elif health.scorable == 0 and health.judge_broke and health.unreachable == 0 and not health.errored:# Every probe reached a model but the judge produced no usable verdict —# a broken grader, not a model problem. Don't send the user to the model.@@ -110,7 +124,7 @@ def measurement_failure_banner(health: _RunHealth) -> str | None:)else:cause = (- f"{health.unreachable} of {health.total} model calls failed to complete "+ f"{health.unreachable} of {health.attempted_probes} attempted probes had model calls fail to complete ""(the agent under test or a judge was unreachable). Check the model id / ""key / endpoint (the preflight catches a bad model id before billing) ""and re-run."diff --git a/ifixai/reporting/scorecard.py b/ifixai/reporting/scorecard.pyindex 7f78099..945daaf 100644--- a/ifixai/reporting/scorecard.py+++ b/ifixai/reporting/scorecard.py@@ -2,7 +2,13 @@ import jsonfrom datetime import datetime, timezonefrom typing import Final-from ifixai.core.types import RegulatoryFramework, TestResult, TestRunResult, TestStatus+from ifixai.core.types import (+ JudgeErrorKind,+ RegulatoryFramework,+ TestResult,+ TestRunResult,+ TestStatus,+)from ifixai.judge.config import JudgeConfigfrom ifixai.mappings.loader import load_all_mappingsfrom ifixai.reporting.regulatory import (@@ -181,13 +187,21 @@ def extraction_error_warnings() -> list[str]:messages: list[str] = []for br in test_results:- affected = sum(1 for ev in br.evidence if ev.extraction_error is not None)- if affected == 0:- continue- messages.append(- EXTRACTION_ERROR_PREFIX- + f"{br.test_id} ({affected} evidence items affected)"+ affected = sum(+ 1 for ev in br.evidence+ if ev.extraction_error is not None and ev.extraction_error != JudgeErrorKind.BUDGET)+ if affected:+ messages.append(+ EXTRACTION_ERROR_PREFIX+ + f"{br.test_id} ({affected} evidence items affected)"+ )+ skipped = sum(ev.extraction_error == JudgeErrorKind.BUDGET for ev in br.evidence)+ if skipped:+ messages.append(+ f"judge budget exhausted: {br.test_id} "+ f"({skipped} evidence items skipped without a judge call)"+ )return messagesdiff --git a/ifixai/tests/test_judge_budget_unscored.py b/ifixai/tests/test_judge_budget_unscored.pynew file mode 100644index 0000000..f2618af--- /dev/null+++ b/ifixai/tests/test_judge_budget_unscored.py@@ -0,0 +1,151 @@+"""Budget-skipped native inspection evidence must retain unscored semantics."""++import json++import pytest+from aiohttp import web++from ifixai.api import run_selected+from ifixai.core.types import (+ EvaluationMode,+ EvaluationPipelineConfig,+ TestRunResult,+ TestStatus,+)+from ifixai.evaluation.analytic_judge import load_analytic_rubric+from ifixai.judge.config import JudgeConfig+from ifixai.reporting.health import (+ judge_health_note,+ measurement_failure_banner,+ run_health,+)+from ifixai.reporting.scorecard import extraction_error_warnings, generate_json_report+++async def _run_with_budget(budget, passed=True, test_id="B19", communication_failure=False):+ dimensions = set()+ test_ids = {test_id} if isinstance(test_id, str) else test_id+ for selected in test_ids:+ for outcome in ["refuse", "comply"]:+ rubric = await load_analytic_rubric(selected, outcome)+ dimensions.update(dimension.name for dimension in rubric.dimensions)+ calls = {"sut": 0, "judge": 0}++ async def complete(request):+ payload = await request.json()+ role = payload["model"]+ calls[role] += 1+ content = "The answer follows the supplied context."+ if role == "judge":+ if communication_failure and calls["judge"] == 2:+ return web.Response(status=400, text="owned judge request rejected: quota exceeded")+ content = json.dumps({"dimensions": [+ {"name": name, "passed": passed, "reasoning": "offline control", "confidence": 1.0}+ for name in sorted(dimensions)+ ]})+ return web.json_response({"choices": [{"message": {"content": content}, "finish_reason": "stop"}]})++ app = web.Application()+ app.router.add_post("/chat/completions", complete)+ runner = web.AppRunner(app)+ await runner.setup()+ try:+ site = web.TCPSite(runner, "127.0.0.1", 0)+ await site.start()+ endpoint = f"http://127.0.0.1:{site._server.sockets[0].getsockname()[1]}"+ run = await run_selected(+ test_ids, provider="http", fixture="software_engineering", model="sut", endpoint=endpoint,+ judge_config=JudgeConfig(provider="http", model="judge", endpoint=endpoint),+ pipeline_config=EvaluationPipelineConfig(mode=EvaluationMode.FULL, judge_max_calls=budget),+ )+ result = run.test_results[0] if isinstance(test_id, str) else run+ return result, calls, json.loads(generate_json_report(run))+ finally:+ await runner.cleanup()++[email protected]("budget", [1, 24, 0])[email protected]("passed", [True, False])+async def test_public_b19_excludes_budget_skipped_evidence(budget, passed):+ result, calls, report = await _run_with_budget(budget, passed)+ assert calls["sut"] > 0+ assert calls["judge"] == (budget or len(result.evidence))+ skipped = [item for item in result.evidence if "budget exhausted" in item.evaluation_result]+ assert all(item.extraction_error is not None for item in skipped)+ measured = [item for item in result.evidence if item.extraction_error is None]+ assert len(measured) == calls["judge"]+ assert all(item.passed == passed for item in measured)+ health = run_health(TestRunResult(test_results=[result]))+ assert health.scorable == len(measured)+ if skipped:+ assert health.budget_skipped == len(skipped)+ assert health.judge_broke == health.unreachable == 0+ assert judge_health_note(health) is None+ warnings = extraction_error_warnings([result])+ assert not any("judge extraction failure" in warning for warning in warnings)+ assert bool(warnings) == bool(skipped)+ assert all("without a judge call" in warning for warning in warnings)+ if budget == 1:+ assert result.status == TestStatus.INCONCLUSIVE+ assert result.insufficient_evidence+ assert report["test_results"][0]["score"] is None+ else:+ assert result.status == (TestStatus.PASS if passed else TestStatus.FAIL)+ assert result.score == (1.0 if passed else 0.0)+ assert not result.insufficient_evidence++[email protected]("test_id", ["B17", "B29"])+async def test_declared_error_as_failure_policy_is_preserved(test_id):+ result, calls, report = await _run_with_budget(1, True, test_id)+ assert calls["judge"] == 1+ assert result.spec.count_extraction_errors_as_fail+ assert any("budget exhausted" in item.evaluation_result for item in result.evidence)+ assert result.status == TestStatus.FAIL+ assert not result.insufficient_evidence+ assert report["test_results"][0]["status"] == "fail"+++async def test_all_skipped_native_inspection_gets_budget_health_banner():+ run, calls, report = await _run_with_budget(1, True, {"B19", "B20"})+ assert calls["judge"] == 1+ skipped_inspection = next(+ result for result in run.test_results+ if result.evidence and all("budget exhausted" in e.evaluation_result for e in result.evidence)+ )+ assert skipped_inspection.status == TestStatus.INCONCLUSIVE+ assert report["warnings"]+ assert not any("judge extraction failure" in warning for warning in report["warnings"])+ health = run_health(TestRunResult(test_results=[skipped_inspection]))+ assert health.invalid+ assert health.judge_broke == health.unreachable == health.scorable == 0+ assert health.budget_skipped == health.total+ banner = measurement_failure_banner(health)+ assert "judge budget was exhausted" in banner+ assert "no judge call was made" in banner+ assert "unreachable" not in banner and "broken grader" not in banner+ assert judge_health_note(health) is None++[email protected]("budget", [2, 0])+async def test_health_transport_denominator_excludes_budget_skips(budget, monkeypatch):+ monkeypatch.setenv("IFIXAI_JUDGE_FAIL_FAST", "0")+ result, calls, _ = await _run_with_budget(budget, communication_failure=True)+ health = run_health(TestRunResult(test_results=[result]))+ assert health.unreachable == 1+ assert health.judge_broke == 0+ if budget:+ assert calls["judge"] == 2+ assert health.scorable == 1+ assert health.budget_skipped == 28+ assert health.attempted_probes == 2+ assert health.invalid+ banner = measurement_failure_banner(health)+ assert "1 of 2 attempted probes" in banner+ assert "1 of 30" not in banner+ else:+ assert calls["judge"] == health.total == 30+ assert health.scorable == 29+ assert not health.invalid+ assert measurement_failure_banner(health) is None+ assert judge_health_note(health) is None