Repository navigation
RestApiTool raises uncaught KeyError when a required path param is omitted #7282
Description
Activity
Picking this one up now — opening a PR shortly. Flagging it here so nobody duplicates the work; if someone is already on it, say so and I will drop mine.
- addedtools[Component] This issue is related to tools[Component] This issue is related to tools
on Sep 28, 2026 Hello @michaelkillgta,
We reproduced this issue in version 2.10.0, and it remains reproducible with this version as well. Furthermore we tested #7283 as well and it should resolve this issue. Could you please test it and provide your feedback?
- addedrequest clarification[Status] The maintainer need clarification or more information from the author[Status] The maintainer need clarification or more information from the author
on Sep 29, 2026 Looked at #7283. Catching the KeyError from
_prepare_request_paramsand returning a structured error matches the report, and the new test checks that the request is not sent and thatuserIdappears in the error.One caveat: any KeyError inside
_prepare_request_paramsis reported as a missing path parameter, even if the missing key is something else. Narrowing that to actual path params would be safer. I reviewed the diff only and have not run the suite.Follow-up after running the tests. On #7283 (
74dda20),test_rest_api_tool.pypassed 100 tests, including the new missing-path-param case.The caveat is real. A required query param named
queryon/search?q={query}, supplied asquery=hello, returnsMissing required path parameter 'query'and never makes the HTTP call. AKeyErrorraised from_default_headersis reported the same way.- added a commit that references this issue
on Oct 9, 2026
Description
FunctionToolreturns{"error": ...}when mandatory args are missing so the model can retry.RestApiToolmaps filled args intopath_params, then doesself.endpoint.path.format(**path_params)in_prepare_request_params. An omitted required path parameter leaves a template key unset →KeyError(original OpenAPI name, e.g.'userId').RestApiTool.callonly catchesTimeoutException/HTTPStatusError, so the agent invocation aborts instead of returning a retryable tool error.Location:
google/adk/tools/openapi_tool/openapi_spec_parser/rest_api_tool.pyEnvironment
google-adk==2.9.2Repro
Observed (
google-adk==2.9.2)/users/{userId}, args{}→KeyError: 'userId'py_namesfor the param includeuser_id(declaration expects snake_case), but missing value still crashes viaformatExpected
Missing required path params should return a structured tool error (mirror
FunctionTool._get_mandatory_args) so the model can retry, not abort the agent run.Suggested fix
Before
format, verify every{placeholder}in the path is present; on miss return{"error": "missing path parameter …"}. Optionally catchKeyError/ValueErrorfrom_prepare_request_paramsincall.Notes
Nearby RestApiTool crashes #7164 (header type) and #7206 (non-UTF-8 body) are different sites. Happy to open a PR.