Skip to content

Automatic function calling rejects datetime and UUID arguments #3331

Open

Description

@campoy

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!

Activity

  1. added a commit that references this issue on Nov 10, 2026
    d162b63
  2. added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Nov 11, 2026
  3. Venkaiahbabuneelam commented on Nov 11, 2026

    @Venkaiahbabuneelam

    Hi @campoy, Thanks for reaching out us!

    I have successfully reproduced the issue and When using Automatic Function Calling in google-genai, any Python tool function with datetime or UUID parameters never runs (ran: False) because the SDK schema tells the Gemini model to send date-time and UUID values as JSON strings, but convert_if_exist_pydantic_model() checks is instance without parsing those strings into datet-ime or UUID objects, causing the SDK to reject the arguments with an UnknownFunctionCallArgumentError, we will file a bug internally.

    Thanks

  4. added a commit that references this issue on Nov 13, 2026
    a9e7618
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions