From 6bd3d4090e1fe75d61cf4f3735c06261a0152dd2 Mon Sep 17 00:00:00 2001 From: Yvonne Yu Date: Fri, 23 Oct 2026 06:30:58 -0700 Subject: [PATCH] chore: log warning if users don't use json schema for FunctionDeclaration.from_callable or FunctionDeclaration.from_callable_with_api_option. Fixes #3105 PiperOrigin-RevId: 1005552350 --- google/genai/types.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/google/genai/types.py b/google/genai/types.py index 86fd26fd1..70fdf9227 100644 --- a/google/genai/types.py +++ b/google/genai/types.py @@ -166,6 +166,7 @@ def __getattr__(name: str) -> Any: _response_code_execution_warning_logged = False _live_server_text_warning_logged = False _live_server_data_warning_logged = False +_from_callable_with_api_option_warning_logged = False T = typing.TypeVar('T', bound='GenerateContentResponse') @@ -4914,6 +4915,16 @@ def from_callable_with_api_option( f'Unsupported api_option value: {api_option}. Supported api_option' f' value is one of: {supported_api_options}.' ) + global _from_callable_with_api_option_warning_logged + if ( + not use_json_schema + and not _from_callable_with_api_option_warning_logged + ): + logger.warning( + 'use_json_schema is not True, which is not recommended. Parsing a' + ' callable into JSON schema is preferred.' + ) + _from_callable_with_api_option_warning_logged = True from . import _automatic_function_calling_util if use_json_schema: