Skip to content

RestApiTool sends empty or whitespace-only path parameters #8032

Description

@benclarkeio

Describe the Bug:

RestApiTool rejects a missing required path parameter with an InputValidationError that names it (#7282), and rejects . / .. segments in _encode_path_param() (#7065). Both come back to the model as a structured tool error it can retry from.

An empty or whitespace-only value passes both checks. _encode_path_param() percent-encodes it and the request goes out with an empty (or %20) path segment, e.g. /pets//toys or /pets/%20%20/toys. Depending on the server and any proxy in front of it, that becomes a redirect, a 404, a generic validation error, or, where slashes are merged, a request for /pets/toys that can match /pets/{petId} with petId=toys. None of these names the parameter, so the model has nothing to correct and often retries the same call.

Path parameters are always required in OpenAPI and a blank value can't identify a resource, so there's no valid request this would block.

Steps to Reproduce:

from google.adk.errors.input_validation_error import InputValidationError
from google.adk.tools.openapi_tool import OpenAPIToolset

spec = {
    "openapi": "3.0.0",
    "info": {"title": "Pet Store", "version": "1.0.0"},
    "servers": [{"url": "https://petstore.example.com"}],
    "paths": {
        "/pets/{petId}/toys": {
            "get": {
                "operationId": "listToys",
                "parameters": [{
                    "name": "petId",
                    "in": "path",
                    "required": True,
                    "schema": {"type": "string"},
                }],
                "responses": {"200": {"description": "The pet's toys."}},
            }
        }
    },
}

tool = OpenAPIToolset(spec_dict=spec).get_tool("list_toys")
params = tool._operation_parser.get_parameters()
for args in ({}, {"pet_id": ".."}, {"pet_id": ""}, {"pet_id": "  "}):
  try:
    print(repr(args), "->", tool._prepare_request_params(params, args)["url"])
  except InputValidationError as e:
    print(repr(args), "-> InputValidationError:", e)

Expected Behavior:

"" and " " are rejected like a missing value, with an InputValidationError naming the parameter, so RestApiTool.call() returns {"error": ...} and no request is sent.

Observed Behavior:

{} -> InputValidationError: Missing required path parameter 'pet_id'.
{'pet_id': '..'} -> InputValidationError: Path parameter 'petId' must not contain current-directory or parent-directory segments.
{'pet_id': ''} -> https://petstore.example.com/pets//toys
{'pet_id': '  '} -> https://petstore.example.com/pets/%20%20/toys

Proposed fix:

Reject a path parameter value that is empty after stripping whitespace, raising the same InputValidationError as a missing one and naming the parameter. I'm happy to open a PR.

Environment Details:

  • ADK Library Version: main (2.14.0)
  • Desktop OS: macOS
  • Python Version: 3.12

Model Information:

  • Are you using LiteLLM: N/A
  • Which model is being used: N/A

How often has this issue occurred?:

  • Always (100%)

Activity

  1. added theissue type on Nov 9, 2026
  2. surajksharma07 commented on Nov 9, 2026

    @surajksharma07
    Collaborator

    @benclarkeio Reproduced on v2.14.0, and None slips through the same way (goes out as /pets/None/toys).

    As a stopgap until #8034 is merged, one option that worked for me is a small check before the URL is built: drop None so it hits the existing missing-param error, and raise InputValidationError when the value is blank and fills a whole path segment. Could you try that on your side and confirm the model gets the error back and no request goes out?

    Before the PR moves forward, could you also add the Co-authored-by trailer @its-amann asked for on 7dcd392 and give it one more full test run?

  3. benclarkeio commented on Nov 16, 2026

    @benclarkeio
    ContributorAuthor

    @surajksharma07 Thanks for reproducing. That stopgap is what #8034 does: a None path argument is reported as a missing parameter, and a value that leaves a whole segment blank raises an InputValidationError naming the parameter. The tests assert that RestApiTool.call() returns the error without sending a request.

    I've added the Co-authored-by trailer for @its-amann to the None commit (now e44ffed). Could you review #8034?

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

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions