From e3aa281c17bd89d0a5f5d4136e300ea2bfb8ab44 Mon Sep 17 00:00:00 2001 From: Moneeb Arif Date: Wed, 12 Aug 2026 01:31:22 -0700 Subject: [PATCH] fix(evaluation): open eval/session JSON files as UTF-8 Four open() calls in the evaluation module read/write JSON eval data and session files without an explicit encoding, so they fall back to the platform default (e.g. cp1252 on Windows). Eval datasets and sessions routinely contain non-ASCII text (model prompts/responses in other languages, emoji), so on non-UTF-8 locales these calls raise UnicodeDecodeError on read or write mojibake on save. Pass encoding="utf-8" to make the behavior deterministic across platforms, matching the rest of the evaluation module (local_eval_sets_manager, eval_config, local_eval_set_results_manager) which already do this. --- src/google/adk/evaluation/agent_evaluator.py | 6 +++--- src/google/adk/evaluation/evaluation_generator.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/google/adk/evaluation/agent_evaluator.py b/src/google/adk/evaluation/agent_evaluator.py index 8a636acd014..7fb64d0189f 100644 --- a/src/google/adk/evaluation/agent_evaluator.py +++ b/src/google/adk/evaluation/agent_evaluator.py @@ -94,7 +94,7 @@ def __call__(self) -> Awaitable[tuple[BaseAgent, object]]: def load_json(file_path: str) -> Union[Dict[str, Any], List[Any]]: - with open(file_path, "r") as f: + with open(file_path, "r", encoding="utf-8") as f: return cast(Union[Dict[str, Any], List[Any]], json.load(f)) @@ -358,7 +358,7 @@ def migrate_eval_data_to_new_schema( old_eval_data_file, eval_config, initial_session ) - with open(new_eval_data_file, "w") as f: + with open(new_eval_data_file, "w", encoding="utf-8") as f: f.write(eval_set.model_dump_json(indent=2)) @staticmethod @@ -417,7 +417,7 @@ def _get_initial_session( ) -> dict[str, Any]: initial_session: dict[str, Any] = {} if initial_session_file: - with open(initial_session_file, "r") as f: + with open(initial_session_file, "r", encoding="utf-8") as f: initial_session = json.loads(f.read()) return initial_session diff --git a/src/google/adk/evaluation/evaluation_generator.py b/src/google/adk/evaluation/evaluation_generator.py index 54634e9dbf1..60e579155a8 100644 --- a/src/google/adk/evaluation/evaluation_generator.py +++ b/src/google/adk/evaluation/evaluation_generator.py @@ -436,7 +436,7 @@ def generate_responses_from_session( """ results = [] - with open(session_path, "r") as f: + with open(session_path, "r", encoding="utf-8") as f: session_data = Session.model_validate_json(f.read()) logger.info("Loaded session %s", session_path)