adk-samples icon indicating copy to clipboard operation
adk-samples copied to clipboard

[BUG]: data-science agent - ValueError with pd.isna on array values and Context variable not found error

Open leebaro opened this issue 1 year ago • 1 comments

Name of sample affected

data-science-agent

Description of issue

We're encountering two separate issues in our data-science-agent:

  1. ValueError with pandas.isna: When processing array values in the _serialize_value_for_sql function, we get a ValueError because pd.isna(value) is being called on an array without proper handling.

  2. Context variable not found: During agent execution, the system fails with KeyError: 'Context variable not found: post_id.' because a template is trying to access a variable that isn't in the session state.

Environment

  • OS & Architecture: macOS (Apple Silicon/arm64)
  • Python version: 3.12

Reproduction steps or code

For the first issue, the error occurs in the _serialize_value_for_sql function:

def _serialize_value_for_sql(value):
    """Serializes a Python value from a pandas DataFrame into a BigQuery SQL literal."""
    # if pd.isna(value):
    #     return "NULL"
    if pd.isna(value):
        return "NULL"    
    if isinstance(value, str):
        # More code...

The problem is that pd.isna(value) on array values returns an array of boolean values, which can't be directly evaluated in an if statement.

Error log

File "/data-science-agent/app/sub_agents/bigquery/tools.py", line 47, in _serialize_value_for_sql
    if pd.isna(value):
       ^^^^^^^^^^^^^^
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

For the second issue:

2025-08-21 16:35:57,227 - ERROR - adk_web_server.py:857 - Error in event_generator: 'Context variable not found: `post_id`.'
Traceback (most recent call last):
  File "/data-science-agent/.venv/lib/python3.12/site-packages/google/adk/cli/adk_web_server.py", line 843, in event_generator
    async for event in runner.run_async(
  # ... [truncated stack trace]
  File "/data-science-agent/.venv/lib/python3.12/site-packages/google/adk/utils/instructions_utils.py", line 106, in _replace_match
    raise KeyError(f'Context variable not found: `{var_name}`.')
KeyError: 'Context variable not found: `post_id`.'

This occurs because a template is trying to access the post_id variable which doesn't exist in the session state.

leebaro avatar Aug 21 '25 07:08 leebaro

take

manikrishna-m avatar Sep 18 '25 21:09 manikrishna-m