From d752bafc6ae9e1436971baf6032e59575a3d0e56 Mon Sep 17 00:00:00 2001 From: Nilesh Patil <128893479+nileshpatil6@users.noreply.github.com> Date: Sat, 16 May 2026 20:11:12 +0530 Subject: [PATCH] fix: support functools.partial objects as tools in t_tool() Fixes #907 inspect.isfunction() returns False for functools.partial objects, so passing a partial to tools= would silently fall through to the else branch and return the partial object unchanged. The API then received an invalid tool object and rejected it with 400 INVALID_ARGUMENT. Add functools.partial to the callable check so partial functions get wrapped in a FunctionDeclaration the same way regular functions do. --- google/genai/_transformers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/google/genai/_transformers.py b/google/genai/_transformers.py index c36524100..edc863602 100644 --- a/google/genai/_transformers.py +++ b/google/genai/_transformers.py @@ -18,6 +18,7 @@ import base64 from collections.abc import Iterable, Mapping from enum import Enum, EnumMeta +from functools import partial as _partial import inspect import io import logging @@ -959,7 +960,7 @@ def t_tool( ) -> Optional[Union[types.Tool, Any]]: if not origin: return None - if inspect.isfunction(origin) or inspect.ismethod(origin): + if inspect.isfunction(origin) or inspect.ismethod(origin) or isinstance(origin, _partial): return types.Tool( function_declarations=[ types.FunctionDeclaration.from_callable(