Skip to content

OpenAPI tool: generate_return_doc crashes on non-numeric response keys (default, NXX) #6174

@garyzava

Description

@garyzava

Describe the bug

PydocHelper.generate_return_doc builds its sorted response list with
sorted(responses.items(), key=lambda item: int(item[0])). OpenAPI 3.x allows
non-numeric keys in the Responses Object — default and the range patterns
1XX/2XX/3XX/4XX/5XX. When any of those keys is present, int(item[0])
raises ValueError, so generating a tool from an otherwise valid OpenAPI spec
crashes.

To Reproduce

from fastapi.openapi.models import Response, Schema, MediaType
from google.adk.tools.openapi_tool.common.common import PydocHelper

responses = {
    "200": Response(description="OK", content={"application/json": MediaType(schema=Schema(type="string"))}),
    "default": Response(description="Error response"),
}
PydocHelper.generate_return_doc(responses)
# ValueError: invalid literal for int() with base 10: 'default'

Expected behavior

Non-numeric response keys should be ignored for return-type hinting (the code
already keeps only 2xx responses with content on the very next line), so the
function should return the doc for the 200 response instead of crashing.

Desktop

  • google-adk 2.1.0 and later; still present on main as of 2026-06-10

Additional context

operation_parser already filters startswith('2') before consuming the keys;
applying the same guard here keeps the two paths consistent.

Metadata

Metadata

Assignees

Labels

tools[Component] This issue is related to tools

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions