IntEnum tool parameters produce an invalid function declaration: integer values in a STRING enum
- Lenguaje dominante
- Python
- Estrellas
- 21.5k
- Forks
- 4k
- Merge medio
- 1 d 22 h
- PR fusionados (30 d)
- 31
Descripción
## 🔴 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:**
```text
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': }
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:**
```python
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%)
Guía de contribución
Evaluación
Este issue todavía no se ha evaluado.