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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions