Skip to content

IntEnum tool parameters produce an invalid function declaration: integer values in a STRING enum #6978

Description

@MarcHuang168

🔴 Required Information

Describe the Bug:
When a tool function has a parameter annotated with an enum.IntEnum, the generated function declaration sets type: STRING but fills enum with the raw integer values (e.g. [1, 2]). google.genai.types.Schema.enum is typed list[str], so the declaration is invalid by the SDK's own contract: building the same schema through the constructor raises a ValidationError, and serializing the ADK-built one emits PydanticSerializationUnexpectedValue warnings. The invalid value only gets through because the parser assigns schema.enum = [...] after construction, which bypasses validation.

Steps to Reproduce:

  1. pip install google-adk
  2. Run the snippet under Minimal Reproduction Code
  3. Observe the emitted schema and the serializer warnings

Expected Behavior:
The declaration is valid for types.Schema — e.g. the enum values are strings (["1", "2"], or the member names), consistent with type: STRING.

Observed Behavior:

UserWarning: Pydantic serializer warnings:
  PydanticSerializationUnexpectedValue(Expected `str` - serialized value may not be as expected [field_name='enum', input_value=1, input_type=int])
  PydanticSerializationUnexpectedValue(Expected `str` - serialized value may not be as expected [field_name='enum', input_value=2, input_type=int])
ADK emits: {'enum': [1, 2], 'type': <Type.STRING: 'STRING'>}
types.Schema rejects it: ValidationError

Environment Details:

  • ADK Library Version (pip show google-adk): 2.8.0
  • Desktop OS: macOS (arm64)
  • Python Version (python -V): 3.14.7

Model Information:

  • Are you using LiteLLM: No
  • Which model is being used: N/A (reproduces at declaration-build time, no model call needed)

🟡 Optional Information

Regression:
Unknown.

Logs:
See Observed Behavior above.

Screenshots / Video:
N/A

Additional Context:
str-valued enums work correctly; only non-string enum values are affected. The relevant code is the Enum branch in _function_parameter_parse_util._parse_schema_from_parameter (schema.enum = [e.value for e in param.annotation]).

I'd be happy to submit a PR for this. Since it involves a choice (stringify the values vs. use member names, and how the argument is mapped back to the enum on the call path), I'd appreciate guidance on the preferred approach before opening one, per the contributing guide. Reported with AI assistance; reproduced and reviewed by me.

Minimal Reproduction Code:

import enum
from google.genai import types
from google.adk.tools._automatic_function_calling_util import from_function_with_options


class Level(enum.IntEnum):
    LOW = 1
    HIGH = 2


def set_level(level: Level) -> str:
    """Set the level.

    Args:
        level: the level to set
    """
    return "ok"


decl = from_function_with_options(set_level)
print("ADK emits:", decl.parameters.properties["level"].model_dump(exclude_none=True))

# The same schema is rejected when built through the public constructor
try:
    types.Schema(type="STRING", enum=[1, 2])
except Exception as e:
    print("types.Schema rejects it:", type(e).__name__)

How often has this issue occurred?:

  • Always (100%)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

request clarification[Status] The maintainer need clarification or more information from the authortools[Component] This issue is related to tools

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions