Skip to content

OpenAPIToolset stopped working in (likely all?) ADK versions after recent FastAPI release #2991

@wietsevenema

Description

@wietsevenema

With a fresh adk install, any OpenAPI spec crashes OpenAPIToolset. Pinning FastAPI to 0.116 is a mitigation. I think this affects most ADK versions, since we have loose version constraints on FastAPI.

Reproduce

from google.adk.agents.llm_agent import Agent
from google.adk.tools.openapi_tool import OpenAPIToolset

openapi_spec = """{
  "openapi": "3.0.0",
  "info": {
    "title": "Minimal Test API",
    "version": "1.0.0"
  },
  "paths": {
    "/hello": {
      "get": {
        "summary": "Returns a greeting",
        "operationId": "hello",
        "responses": {
          "200": {
            "description": "A successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}"""

adventure_game_toolset = OpenAPIToolset(
    spec_str=openapi_spec,
)

root_agent = Agent(
    model="gemini-2.5-flash",
    name="root_agent",
    description="An agent",
    instruction="Do your best",
    tools=[adventure_game_toolset]
)

Stacktrace

2025-09-21 23:11:26,944 - INFO - envs.py:47 - Loaded .env file for demo-agent at /demo-agent/.env
2025-09-21 23:11:26,944 - INFO - envs.py:47 - Loaded .env file for demo-agent at /demo-agent/.env
2025-09-21 23:11:26,946 - ERROR - adk_web_server.py:1076 - Error in event_generator: 2 validation errors for Schema
type.literal['array','boolean','integer','null','number','object','string']
  Input should be 'array', 'boolean', 'integer', 'null', 'number', 'object' or 'string' [type=literal_error, input_value='Any', input_type=str]
    For further information visit https://errors.pydantic.dev/2.11/v/literal_error
type.list[literal['array','boolean','integer','null','number','object','string']]
  Input should be a valid list [type=list_type, input_value='Any', input_type=str]
    For further information visit https://errors.pydantic.dev/2.11/v/list_type
Traceback (most recent call last):
  File "../python3.12/site-packages/google/adk/cli/adk_web_server.py", line 1056, in event_generator
    runner = await self.get_runner_async(req.app_name)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "../python3.12/site-packages/google/adk/cli/adk_web_server.py", line 327, in get_runner_async
    agent_or_app = self.agent_loader.load_agent(app_name)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "../python3.12/site-packages/google/adk/cli/utils/agent_loader.py", line 234, in load_agent
    agent_or_app = self._perform_load(agent_name)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "../python3.12/site-packages/google/adk/cli/utils/agent_loader.py", line 207, in _perform_load
    if root_agent := self._load_from_module_or_package(actual_agent_name):
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "../python3.12/site-packages/google/adk/cli/utils/agent_loader.py", line 108, in _load_from_module_or_package
    raise e
  File "../python3.12/site-packages/google/adk/cli/utils/agent_loader.py", line 70, in _load_from_module_or_package
    module_candidate = importlib.import_module(agent_name)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/venema/.pyenv/versions/3.12.5/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/demo-agent/__init__.py", line 1, in <module>
    from . import agent
  File "/demo-agent/agent.py", line 37, in <module>
    adventure_game_toolset = OpenAPIToolset(
                             ^^^^^^^^^^^^^^^
  File "../python3.12/site-packages/google/adk/tools/openapi_tool/openapi_spec_parser/openapi_toolset.py", line 109, in __init__
    self._tools: Final[List[RestApiTool]] = list(self._parse(spec_dict))
                                                 ^^^^^^^^^^^^^^^^^^^^^^
  File "../python3.12/site-packages/google/adk/tools/openapi_tool/openapi_spec_parser/openapi_toolset.py", line 153, in _parse
    operations = OpenApiSpecParser().parse(openapi_spec_dict)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "../python3.12/site-packages/google/adk/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.py", line 73, in parse
    operations = self._collect_operations(openapi_spec_dict)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "../python3.12/site-packages/google/adk/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.py", line 127, in _collect_operations
    operation_parser = OperationParser(operation)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "../python3.12/site-packages/google/adk/tools/openapi_tool/openapi_spec_parser/operation_parser.py", line 65, in __init__
    self._process_return_value()
  File "../python3.12/site-packages/google/adk/tools/openapi_tool/openapi_spec_parser/operation_parser.py", line 169, in _process_return_value
    return_schema = Schema(type='Any')
                    ^^^^^^^^^^^^^^^^^^
  File "../python3.12/site-packages/pydantic/main.py", line 253, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 2 validation errors for Schema
type.literal['array','boolean','integer','null','number','object','string']
  Input should be 'array', 'boolean', 'integer', 'null', 'number', 'object' or 'string' [type=literal_error, input_value='Any', input_type=str]
    For further information visit https://errors.pydantic.dev/2.11/v/literal_error
type.list[literal['array','boolean','integer','null','number','object','string']]
  Input should be a valid list [type=list_type, input_value='Any', input_type=str]
    For further information visit https://errors.pydantic.dev/2.11/v/list_type

This error points here - which seems to be correct. Schema(type='Any') isn't valid.

This was introduced by https://github.com/fastapi/fastapi/pull/13639/files#diff-4939896f79697822446463d5d6dfbf7a0ea5805c46565d355c7305d86f3405c7R126

Mitigation

Pin FastAPI to 0.116

Metadata

Metadata

Assignees

Labels

bot triaged[Bot] This issue is triaged by ADK bottools[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