From 3c49061197ad54727f9b89a8c344f87febe4b8d0 Mon Sep 17 00:00:00 2001 From: Aniket Kumar <86551851+aniketkrs@users.noreply.github.com> Date: Wed, 30 Sep 2026 09:33:27 +0530 Subject: [PATCH] fix: return structured tool error when a required path param is missing --- .../openapi_spec_parser/rest_api_tool.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/google/adk/tools/openapi_tool/openapi_spec_parser/rest_api_tool.py b/src/google/adk/tools/openapi_tool/openapi_spec_parser/rest_api_tool.py index 527095f5366..a68eacc780b 100644 --- a/src/google/adk/tools/openapi_tool/openapi_spec_parser/rest_api_tool.py +++ b/src/google/adk/tools/openapi_tool/openapi_spec_parser/rest_api_tool.py @@ -16,6 +16,7 @@ import logging import ssl +import string from typing import Any from typing import Callable from typing import Dict @@ -460,6 +461,19 @@ def _prepare_request_params( # Construct URL base_url = self.endpoint.base_url or "" base_url = base_url[:-1] if base_url.endswith("/") else base_url + # Fail closed with a structured, retryable tool error when a required + # path placeholder was not provided: str.format() would otherwise + # raise an uncaught KeyError that aborts the whole agent invocation. + missing_path_params = [ + field_name + for _, field_name, _, _ in string.Formatter().parse(self.endpoint.path) + if field_name and field_name not in path_params + ] + if missing_path_params: + raise InputValidationError( + f"Missing required path parameter(s) {missing_path_params} for path" + f" template '{self.endpoint.path}'." + ) url = f"{base_url}{self.endpoint.path.format(**path_params)}" # Move query params embedded in the path template itself (now that path