1515import inspect
1616import logging
1717from typing import Any , Dict , Mapping , Optional
18- from pydantic import ValidationError
1918
2019import toolbox_core
2120from fastapi .openapi .models import (
3231from google .adk .tools .base_tool import BaseTool
3332from google .adk .tools .tool_context import ToolContext
3433from google .genai .types import FunctionDeclaration , Schema , Type
34+ from pydantic import ValidationError
3535from toolbox_core .protocol import AdditionalPropertiesSchema , ParameterSchema
3636from toolbox_core .tool import ToolboxTool as CoreToolboxTool
3737from typing_extensions import override
@@ -50,9 +50,9 @@ def __init__(
5050 adk_token_getters : Optional [Mapping [str , Any ]] = None ,
5151 ):
5252 """Args:
53- core_tool: The underlying toolbox_core.py tool instance.
54- auth_config: Credential configuration to handle interactive flows.
55- adk_token_getters: Tool-specific auth token getters.
53+ core_tool: The underlying toolbox_core.py tool instance.
54+ auth_config: Credential configuration to handle interactive flows.
55+ adk_token_getters: Tool-specific auth token getters.
5656 """
5757 name = getattr (core_tool , "__name__" , None )
5858 if not name :
@@ -216,8 +216,7 @@ async def run_async(
216216 ):
217217 self ._core_tool = self ._core_tool .add_auth_token_getter (
218218 s ,
219- lambda t = creds .oauth2 .id_token
220- or creds .oauth2 .access_token : t ,
219+ lambda t = creds .oauth2 .id_token or creds .oauth2 .access_token : t ,
221220 )
222221 try :
223222 if tool_context ._invocation_context .credential_service :
@@ -270,12 +269,12 @@ async def run_async(
270269
271270 try :
272271 return await self ._core_tool (** args )
273- except (TypeError , PermissionError , ValueError , ValidationError ) as e :
274- # Propagate framework -level errors to ensure compatibility with existing tests
272+ except (TypeError , PermissionError ) as e :
273+ # Propagate system -level errors
275274 raise e
276- except Exception as e :
277- # Catch unexpected tool execution errors and return as a structured dictionary
278- # This handles cases like remote tool crashes or server errors gracefully for LLMs
275+ except ( ValueError , ValidationError , Exception ) as e :
276+ # Catch tool execution and validation errors and return as a structured dictionary
277+ # This handles cases like invalid parameters, tool crashes, or server errors
279278 logging .warning (
280279 "Toolbox tool '%s' execution failed: %s" , self .name , e , exc_info = True
281280 )
0 commit comments