Skip to content

fix: return structured tool error when a required path param is missing - #7352

Open
aniketkrs wants to merge 1 commit into
google:mainfrom
aniketkrs:fix/rest-api-tool-missing-path-param
Open

aniketkrs wants to merge 1 commit into
google:mainfrom
aniketkrs:fix/rest-api-tool-missing-path-param

Conversation

@aniketkrs

@aniketkrs aniketkrs commented Sep 30, 2026 •

Copy link
Copy Markdown

User impact

When the model omits a required OpenAPI path parameter, the RestApiTool call raises an uncaught KeyError that aborts the entire agent invocation. The model never receives retry guidance, so the run dies instead of recovering.

Fixes #7282.

Technical cause

RestApiTool._prepare_request_params builds the URL with self.endpoint.path.format(**path_params) (rest_api_tool.py:463). If a {placeholder} was not supplied, str.format() raises KeyError. The caller in call() only converts InputValidationError into a structured tool error (rest_api_tool.py:610-613), so the KeyError escapes and ends the run.

Fix

Before formatting, collect the template's placeholders with string.Formatter().parse() (which correctly ignores escaped {{/}}) and raise InputValidationError listing any that are missing. The existing call() handler already converts InputValidationError into the retryable {"error": ...} tool response, so the model gets a structured error naming exactly which path parameters it must supply.

Testing plan

  • Existing suite: ran pytest tests/unittests/tools/openapi_tool/openapi_spec_parser/test_rest_api_tool.py on this branch — 94 passed; the same 5 tests fail identically on pristine upstream main (pre-existing environment failures in httpx URL parsing of test fixtures, unrelated to this change).
  • Before/after regression (offline script, no network): constructed a RestApiTool over path template /users/{user_id} with a path ApiParameter. On upstream main, omitting user_id raised an uncaught KeyError: 'user_id'; on this branch it raises InputValidationError("Missing required path parameter(s) ['user_id'] ..."), which call() already converts into the structured retryable tool error. Control with user_id supplied builds https://example.com/users/abc on both.

@google-cla

google-cla Bot commented Sep 30, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RestApiTool raises uncaught KeyError when a required path param is omitted

2 participants