fix(optimization): handle None metric scores in LocalEvalSampler#5415
Open
JesserHamdaoui wants to merge 3 commits intogoogle:mainfrom
Open
fix(optimization): handle None metric scores in LocalEvalSampler#5415JesserHamdaoui wants to merge 3 commits intogoogle:mainfrom
JesserHamdaoui wants to merge 3 commits intogoogle:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5403
Summary
When running
adk optimize, if a metric evaluation fails (e.g., due to a transient API error, missing rubrics, or a malformedJSONDecodeErrorresponse from the LLM judge),local_eval_service.pygracefully catches the exception and returns anEvaluationResultwith aNonescore andNOT_EVALUATEDstatus.However,
LocalEvalSampler._extract_eval_datasubsequently attempts to unconditionally round this value, resulting in aTypeError: type NoneType doesn't define __round__ method, which crashes the entire optimization loop rather than safely skipping or reporting the failed case.Changes
google/adk/optimization/local_eval_sampler.py: Guarded the metric score rounding step in_extract_eval_data."score": round(eval_metric_result.score, 2)"score": round(eval_metric_result.score, 2) if eval_metric_result.score is not None else NoneNonevalue in the diagnostic trace data for failed evals.Huge shoutout to the issue author @msteiner-google for the detailed bug report, root cause analysis, and for suggesting the fix!
Motivation
Optimization loops can run for a long time and make dozens of LLM calls. If a single evaluation case fails due to an intermittent network issue or a temporary rate limit, the
NOT_EVALUATEDstatus is the correct fallback. Crashing the entireadk optimizerun because of a missingNonecheck wastes compute, time, and API quotas. By preservingNone, the optimizer can safely continue and log that the metric did not produce a score.Test plan
Unit Tests:
test_extract_eval_data_preserves_none_metric_scoreintests/unittests/optimization/local_eval_sampler_test.pyto verify that_extract_eval_datapreserves"score": Noneand retains the properNOT_EVALUATEDstatus without throwing aTypeError.uv run pytest tests/unittests/optimization/local_eval_sampler_test.py::test_extract_eval_data_preserves_none_metric_score -q(Result: 1 passed).Manual Reproduction & Verification:
Nonescore during the evaluation step.TypeError: type NoneType doesn't define __round__ method. After applying the fix in this PR, the optimizer safely handled theNonescores and ran to completion without crashing.Used the hello_world example from the provided samples and followed the optimization documentation. Then added
patch_and_run.pyfile in my local environment to force the eval failure