fix(eval): handle None score in LocalEvalSampler to prevent TypeError crash#5420
fix(eval): handle None score in LocalEvalSampler to prevent TypeError crash#5420nileshpatil6 wants to merge 2 commits intogoogle:mainfrom
Conversation
|
Response from ADK Triaging Agent Hello @nileshpatil6, thank you for submitting this pull request! To help us review it more efficiently, could you please add a Additionally, since this is a bug fix, could you please provide logs or a screenshot demonstrating that the You can find more details in our contribution guidelines. Thanks! |
Testing PlanManual verification: from unittest.mock import MagicMock
from google.adk.optimization.local_eval_sampler import LocalEvalSampler
# Simulate a metric result with None score (happens when evaluation fails)
mock_metric_result = MagicMock()
mock_metric_result.score = None
mock_metric_result.metric_name = 'test_metric'
mock_metric_result.eval_status.name = 'NOT_EVALUATED'
mock_per_invocation = MagicMock()
mock_per_invocation.eval_metric_results = [mock_metric_result]
mock_eval_result = MagicMock()
mock_eval_result.eval_metric_result_per_invocation = [mock_per_invocation]Before fix: at After fix: The Reproducing the original crash (as described in issue #5403): trigger a transient API error or |
|
Hi @nileshpatil6 , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Please fix formatting errors by running autoformat.sh |

Problem
When a metric evaluation fails (transient API error, rate limiting,
JSONDecodeError),local_eval_service.pycatches the exception and returns anEvaluationResultwithscore=None. However,local_eval_sampler.pyline 292 then callsround(eval_metric_result.score, 2)unconditionally, crashing with:Fixes #5403
Fix
Guard the
round()call with aNonecheck: