From 61b11ec58db54c0b8ecb66b2a82c868d2337f4d9 Mon Sep 17 00:00:00 2001 From: osushinekotan Date: Wed, 24 Dec 2025 21:19:08 +0900 Subject: [PATCH 1/2] fix: add missing crop function to _DATA_FILE_HELPER_LIB Fixes #4011 --- src/google/adk/flows/llm_flows/_code_execution.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/google/adk/flows/llm_flows/_code_execution.py b/src/google/adk/flows/llm_flows/_code_execution.py index bfa84db69d..9cc4941a9e 100644 --- a/src/google/adk/flows/llm_flows/_code_execution.py +++ b/src/google/adk/flows/llm_flows/_code_execution.py @@ -76,6 +76,10 @@ class DataFileUtil: _DATA_FILE_HELPER_LIB = ''' import pandas as pd +def crop(s: str, max_chars: int = 64) -> str: + """Crops a string to max_chars characters.""" + return s[: max_chars - 3] + '...' if len(s) > max_chars else s + def explore_df(df: pd.DataFrame) -> None: """Prints some information about a pandas DataFrame.""" From b3b138214ba39b5d9bed3f8ac543e7f3c6b3e0c3 Mon Sep 17 00:00:00 2001 From: osushinekotan Date: Wed, 24 Dec 2025 21:38:03 +0900 Subject: [PATCH 2/2] fix: Improve `crop` function logic to correctly handle small `max_chars` values. --- src/google/adk/flows/llm_flows/_code_execution.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/google/adk/flows/llm_flows/_code_execution.py b/src/google/adk/flows/llm_flows/_code_execution.py index 9cc4941a9e..05fc00cdfc 100644 --- a/src/google/adk/flows/llm_flows/_code_execution.py +++ b/src/google/adk/flows/llm_flows/_code_execution.py @@ -77,8 +77,12 @@ class DataFileUtil: import pandas as pd def crop(s: str, max_chars: int = 64) -> str: - """Crops a string to max_chars characters.""" - return s[: max_chars - 3] + '...' if len(s) > max_chars else s + """Crops a string to max_chars characters.""" + if len(s) <= max_chars: + return s + if max_chars >= 3: + return s[:max_chars - 3] + '...' + return s[:max_chars] def explore_df(df: pd.DataFrame) -> None: """Prints some information about a pandas DataFrame."""