Skip to content

RestApiTool raises uncaught KeyError when a required path param is omitted #7282

Description

@michaelkillgta

Description

FunctionTool returns {"error": ...} when mandatory args are missing so the model can retry.

RestApiTool maps filled args into path_params, then does self.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.call only catches TimeoutException / 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.py

Environment

  • google-adk==2.9.2
  • Offline unit repro (no live HTTP)

Repro

# RestApiTool for path /users/{userId} with required path param userId / py_name user_id
# Call with args {} (or missing user_id)
# → KeyError: 'userId'

Observed (google-adk==2.9.2)

  • path /users/{userId}, args {} → KeyError: 'userId'
  • py_names for the param include user_id (declaration expects snake_case), but missing value still crashes via format

Expected

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 catch KeyError/ValueError from _prepare_request_params in call.

Notes

Nearby RestApiTool crashes #7164 (header type) and #7206 (non-UTF-8 body) are different sites. Happy to open a PR.

Activity

  1. chelsealong commented on Sep 25, 2026

    @chelsealong
    Contributor

    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.

  2. michaelkillgta commented on Sep 25, 2026

    @michaelkillgta
    Author

    Thanks for picking this up so quickly — and for the PRs (#7285 / #7284 / #7283). Happy to review or clarify anything from the original repros if useful.

  3. llalitkumarrr commented on Sep 29, 2026

    @llalitkumarrr
    Collaborator

    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?

  4. added
    request clarification[Status] The maintainer need clarification or more information from the author
    on Sep 29, 2026
  5. michaelkillgta commented on Sep 30, 2026

    @michaelkillgta
    Author

    Looked at #7283. Catching the KeyError from _prepare_request_params and returning a structured error matches the report, and the new test checks that the request is not sent and that userId appears in the error.

    One caveat: any KeyError inside _prepare_request_params is 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.

  6. michaelkillgta commented on Sep 30, 2026

    @michaelkillgta
    Author

    Follow-up after running the tests. On #7283 (74dda20), test_rest_api_tool.py passed 100 tests, including the new missing-path-param case.

    The caveat is real. A required query param named query on /search?q={query}, supplied as query=hello, returns Missing required path parameter 'query' and never makes the HTTP call. A KeyError raised from _default_headers is reported the same way.

  7. added a commit that references this issue on Oct 9, 2026
    b930828
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

request clarification[Status] The maintainer need clarification or more information from the authortools[Component] This issue is related to tools

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions