Automatic function calling rejects `datetime` and `UUID` arguments
维护者通常 1 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 75/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
Start by reading convert_if_exist_pydantic_model, which the issue identifies as the point rejecting JSON strings for datetime and UUID, and compare its validation with the pydantic schema generation. Check the automatic function calling tests for argument conversion and add coverage for both types. Done when valid schema-compatible strings reach the tool as converted arguments and the tests pass.
由索引模型根据 Issue 内容生成。
描述
Environment details
- Programming language: Python
- OS: macOS
- Language runtime version: Python 3.12.13
- Package version: google-genai 3.0.0 (same on 2.24.0 and
main)
Steps to reproduce
With automatic function calling, a tool that takes a datetime or a UUID never runs. The declaration tells the model to send a date-time (or uuid) string, the model does, and google-genai rejects it.
This fakes the Gemini API, so no key is needed:
import datetime, json, uuid
import httpx
from google import genai
from google.genai import types
ran, sent = [], []
def schedule(when: datetime.datetime, job_id: uuid.UUID) -> str:
"""Schedule a job."""
ran.append(True)
return "ok"
def fake_gemini(request):
sent.append(json.loads(request.content))
args = {"when": "2026-11-10T09:30:00Z", "job_id": "12345678-1234-5678-1234-567812345678"}
part = {"functionCall": {"name": "schedule", "args": args}} if len(sent) == 1 else {"text": "done"}
return httpx.Response(200, json={"candidates": [{"content": {"role": "model", "parts": [part]}}]})
client = genai.Client(
api_key="fake",
http_options=types.HttpOptions(httpx_client=httpx.Client(transport=httpx.MockTransport(fake_gemini))),
)
client.models.generate_content(
model="gemini-2.5-flash", contents="Schedule it.", config=types.GenerateContentConfig(tools=[schedule])
)
print("declared:", sent[0]["tools"][0]["functionDeclarations"][0]["parameters_json_schema"]["properties"])
print("ran:", bool(ran))
print("sent back:", sent[1]["contents"][-1]["parts"][0]["functionResponse"]["response"])
uv run --no-project --python 3.12 --with "google-genai[httpx]==3.0.0" python repro.py prints:
declared: {'when': {'format': 'date-time', 'type': 'string'}, 'job_id': {'format': 'uuid', 'type': 'string'}}
ran: False
sent back: {'error': "Failed to parse parameter when for function schedule from function call part because function call argument value 2026-11-10T09:30:00Z is not compatible with parameter annotation <class 'datetime.datetime'>."}
job_id fails the same way once when is gone. The call still completes, so nothing says the tool never ran.
The cause: the schema comes from pydantic, but convert_if_exist_pydantic_model ends with isinstance(value, annotation), and a JSON string is never a datetime or UUID. Validating with pydantic too, e.g. pydantic.TypeAdapter(annotation).validate_python(value), would make them agree.
Related, for other types: #2013 (set[str] and other generics, fix in #3295) and #2199 (IntEnum, fix in #3288). From their diffs, neither PR covers datetime or UUID.
Thanks!
- 主要语言
- Python
- 星标
- 4.1k
- 派生
- 1.1k
- 平均合并
- 1 天 20 小时
- 30 天内合并 PR
- 90
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
googleapis/python-genai 的其他 Issue
-
Interactions retries ignore the documented `initial_delay` and `max_delay` defaults可能已有人在做 @Venkaiahbabuneelam 于 4 天前认领。 未关闭priority: p2 status:awaiting user response type: bug
难度 2/5 1-3 小时 新手友好度 68/100
googleapis/python-genai#3317 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Test import module that doesn't exist可能已有人在做 @Venkaiahbabuneelam 于 31 天前认领。 未关闭priority: p2 type: bug
难度 2/5 1-3 小时 新手友好度 66/100
googleapis/python-genai#3122 · 6 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Curated history keeps half a user turn when the model turn is invalid可能已有人在做 @Venkaiahbabuneelam 于 39 天前认领。 未关闭priority: p2 type: bug
难度 2/5 1-3 小时 新手友好度 62/100
googleapis/python-genai#3051 · 3 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
[Bug]: Unsubscripted typing.List and typing.Dict crash convert_if_exist_pydantic_model in AFC可能已有人在做 @Venkaiahbabuneelam 于 39 天前认领。 未关闭priority: p2 type: bug
难度 2/5 1-3 小时 新手友好度 82/100
googleapis/python-genai#3044 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Structured-output continuation merge raises AttributeError: __pydantic_generic_metadata__ when a hop has parsed JSON可能已有人在做 @Venkaiahbabuneelam 于 3 天前认领。 未关闭priority: p2 type: bug
googleapis/python-genai#3350 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 googleapis/python-genai 的全部 Issue
相似的 Issue
-
Email validation accepts a trailing newline可能已有人在做 @marcello-pichini 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
dbt-labs/spark-utils#51 ·
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
bug frontend
难度 2/5 1-3 小时 新手友好度 88/100
vendrabuck/HERD#1419 ·
维护者通常 1 天内回复