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: enforce judge call budget under concurrent evaluations (#135)
Rudy Mizrahi Celekli51da1d6afda9
diff --git a/ifixai/evaluation/pipeline.py b/ifixai/evaluation/pipeline.pyindex ea00e58..7e17b03 100644--- a/ifixai/evaluation/pipeline.py+++ b/ifixai/evaluation/pipeline.py@@ -217,11 +217,14 @@ class EvaluationPipeline:rubric_verdict=veto_verdict,)+ # Reserve the call before the first await. Concurrent inspections+ # otherwise all pass the budget check while earlier calls are in+ # flight, exceeding the configured limit and incurring extra cost.+ self._judge_calls_used += 1try:rubric_verdict = await self._judge.evaluate_with_rubric(response, rubric, context, context_vars)- self._judge_calls_used += 1return PipelineResult(passed=rubric_verdict.passed,evaluation_result=f"judge: {rubric_verdict.verdict} (weighted_score={rubric_verdict.weighted_score:.2f})",@@ -231,7 +234,6 @@ class EvaluationPipeline:)except JudgeCommunicationError as exc:_logger.exception("Judge communication error")- self._judge_calls_used += 1# The judge is not responding / keeps erroring after its bounded# retries. A down judge won't recover, so by default stop the whole# run rather than grind the rest into INCONCLUSIVE at real cost.@@ -249,7 +251,6 @@ class EvaluationPipeline:)except JudgeExtractionError as exc:_logger.exception("Judge extraction error")- self._judge_calls_used += 1return PipelineResult(passed=False,evaluation_result=f"extraction_error: extraction: {exc}",@@ -258,7 +259,6 @@ class EvaluationPipeline:)except JudgeContractError as exc:_logger.exception("Judge contract error")- self._judge_calls_used += 1return PipelineResult(passed=False,evaluation_result=f"extraction_error: contract: {exc}",diff --git a/ifixai/tests/test_pipeline_judge_budget.py b/ifixai/tests/test_pipeline_judge_budget.pynew file mode 100644index 0000000..05e6a57--- /dev/null+++ b/ifixai/tests/test_pipeline_judge_budget.py@@ -0,0 +1,40 @@+import asyncio++from ifixai.core.types import (+ AnalyticRubric,+ EvaluationCriteria,+ EvaluationPipelineConfig,+ RubricVerdict,+)+from ifixai.evaluation.pipeline import EvaluationPipeline+++class SlowJudge:+ def __init__(self):+ self.calls = 0++ async def evaluate_with_rubric(self, response, rubric, context, context_vars):+ self.calls += 1+ await asyncio.sleep(0)+ return RubricVerdict(weighted_score=1.0, passed=True, verdict="pass")+++def test_concurrent_evaluations_respect_judge_call_budget():+ judge = SlowJudge()+ pipeline = EvaluationPipeline(+ EvaluationPipelineConfig(judge_max_calls=1), judge=judge+ )+ rubric = AnalyticRubric(test_id="B01", outcome_type="comply", dimensions=[])++ async def run_both():+ return await asyncio.gather(+ pipeline.evaluate("first", EvaluationCriteria(), rubric),+ pipeline.evaluate("second", EvaluationCriteria(), rubric),+ )++ results = asyncio.run(run_both())++ assert judge.calls == 1+ assert pipeline.judge_calls_used == 1+ assert sum(result.passed for result in results) == 1+ assert sum("budget exhausted" in result.evaluation_result for result in results) == 1