Skip to content

OpenAPIToolset drops additionalProperties dictionary request bodies #8037

Description

@yang0228

Describe the Bug

An OpenAPI JSON request body described as a dictionary, for example type: object with additionalProperties: {type: string} and no named properties, produces an OpenAPIToolset tool with no body parameters. Calls silently send {}, discarding the supplied dictionary.

The declaration itself has properties: {}, so a model is not given a way to supply the dictionary. Passing it as a single body argument or as individual key/value arguments does not preserve it on current main.

Steps to Reproduce

Check out google/adk-python at 1cb926d5b8d702261ec82a26d3f1c4296e0db7d7, install the base dependencies, and run the script below with PYTHONPATH pointing to that checkout's src directory. It uses only httpx.MockTransport; no model, credentials, DNS lookup, or remote API is involved.

import asyncio
import json
import httpx
from google.adk.tools.openapi_tool.openapi_spec_parser.openapi_toolset import OpenAPIToolset

async def main():
    sent = []
    def handle(request):
        sent.append(json.loads(request.content))
        return httpx.Response(200, json={"ok": True})
    spec = {
        "openapi": "3.0.3",
        "info": {"title": "Labels", "version": "1"},
        "servers": [{"url": "https://example.invalid"}],
        "paths": {"/labels": {"post": {
            "operationId": "set_labels",
            "requestBody": {"required": True, "content": {
                "application/json": {"schema": {
                    "type": "object", "additionalProperties": {"type": "string"}
                }}
            }},
            "responses": {"200": {"description": "OK"}}
        }}}
    }
    toolset = OpenAPIToolset(
        spec_dict=spec,
        httpx_client_factory=lambda: httpx.AsyncClient(transport=httpx.MockTransport(handle)),
        allow_private_network_access=True,  # custom local transport; no DNS/network
    )
    tool = toolset.get_tool("set_labels")
    print("declaration:", tool._get_declaration().model_dump(exclude_none=True))
    payload = {"owner": "alice", "team": "red"}
    await tool.run_async(args={"body": payload}, tool_context=None)
    print("expected:", payload)
    print("sent:", sent)

asyncio.run(main())

Expected Behavior

The tool declaration exposes one dictionary body argument and the request contains {"owner":"alice","team":"red"}. Existing request bodies with named properties should retain their current flattened argument interface.

Observed Behavior

declaration parameters_json_schema.properties: {}
expected: {'owner': 'alice', 'team': 'red'}
sent: [{}]

Environment

  • ADK source: 2.14.0 at 1cb926d5b8d702261ec82a26d3f1c4296e0db7d7 (main checked 2026-11-08).
  • Python 3.12.13; macOS; httpx 0.28.1; FastAPI 0.139.2; Pydantic 2.13.4.
  • LiteLLM: no. Model: N/A; this is deterministic tool construction/request serialization.
  • Frequency: every call using this dictionary schema. Regression introduction: not bisected.

Source Trace and Proposed Contribution

OpenAPIToolset → OperationParser._process_request_body expands only schema.properties for every object body. For a dictionary that list is empty. RestApiTool._prepare_request_params then reconstructs an empty object from the absent parameters.

This is distinct from #6991/#6992: the failing schema explicitly has type: object and no composition keywords. It is also distinct from #5364's FunctionDeclaration handling and #7838's missing-schema crash; the media type here has a concrete schema.

I would like to contribute a focused fix that exposes pure dictionary bodies as one body parameter and passes their entries through, while preserving the existing interface for named-property objects. Please let me know if this is already being worked on or if a different representation is preferred. Regression coverage would include typed/free-form dictionaries, empty payloads, parameter-name collisions, and a named-property control.

Activity

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

    @surajksharma07
    Collaborator

    @yang0228 Reproduced this on v2.14.0 too: the tool gets no body arg and {} goes out.

    Until #8038 lands, a workaround that worked on my end is wrapping the dict schema in the spec before passing it to the toolset, e.g. {"allOf": [{"type": "object", "additionalProperties": {"type": "string"}}]}, so ADK exposes a single body arg and sends it as is. Could you give that a try in your actual setup, ideally with a real Gemini call too, and let me know if the dict comes through correctly?

    Since the PR changes the existing open-object behaviour, it’d be good to have that checked end to end before we push it forward for review.

  3. yang0228 commented on Nov 11, 2026

    @yang0228
    ContributorAuthor

    @surajksharma07 I have now checked this with a real Gemini call, using gemini-3.8-flash through the Gemini Developer API, google-genai 2.33.0, and ADK 2.14.0.

    The path is a real LlmAgent / InMemoryRunner → OpenAPIToolset → an ephemeral localhost HTTP server → ADK function response. The model generates the arguments; neither those arguments nor the HTTP transport are mocked. This is a synthetic labels example, not a production application.

    Scenario Main 098eefa24 with the proposed allOf wrapper #8038 at c07b76c4c, without the wrapper
    Typed dictionary {owner: alice, team: red} Passed Passed
    Explicit empty dictionary Passed: the server received two bytes, {} Inconclusive: Gemini returned 503
    Query parameter also named body Inconclusive: Gemini returned 504 Passed on one bounded retry
    Named-property compatibility control Inconclusive: Gemini returned 504 Inconclusive: Gemini returned 503

    For both successful plain-dictionary cases, Gemini generated {"body":{"owner":"alice","team":"red"}}, and the server received the flat JSON {"owner":"alice","team":"red"}. The PR collision case generated {"body":"filter","body_0":{"owner":"alice","team":"red"}}; the server received ?body=filter separately from that same flat JSON. Each completed case also produced the actual ADK function response {"ok":true}.

    One declaration difference remains relevant: allOf exposes the dictionary but leaves body optional even when requestBody.required is true. The dedicated dictionary branch in #8038 preserves requiredness, including body_0 in the collision case. Named-property objects remain on their existing flattened interface.

    The final harness sets ADK's skip_summarization after tool execution and limits each case to one model call; the asserted endpoint is the real function response, not a model-authored final summary. An earlier named-property run reached the correct HTTP payload but its subsequent model-summary request timed out. The remaining 503/high-demand and 504/deadline errors are recorded above, so this is not an all-green real-model matrix. I stopped after the bounded retry rather than repeatedly calling the busy service. Dictionary value-constraint enforcement and production API behavior remain untested.

  4. yang0228 commented on Nov 11, 2026

    @yang0228
    ContributorAuthor

    Follow-up to #8037 (comment): the four previously inconclusive checks have now produced actual tool/HTTP results, using gemini-3.5-flash-lite. The original gemini-3.8-flash requests continued to return connection/503/504 errors, including with a 60-second deadline; an Interactions API control also timed out. Those attempts remain recorded and are not counted as passes.

    To keep the comparison on one model, I ran all eight scenario/snapshot combinations through GenerateContent with the same schemas, prompts, google-genai 2.33.0, and real ADK Runner → OpenAPIToolset → localhost HTTP → function response assertions:

    Scenario Main 098eefa24, dictionary schemas wrapped in allOf #8038 c07b76c4c, direct dictionary schema
    Plain typed dictionary Passed Passed
    Explicit empty dictionary Passed: HTTP body {} Passed: HTTP body {}
    Query parameter also named body Failed: returned and sent a JSON string Passed: returned and sent an object
    Named-property control, unwrapped in both runs Passed; flattened arguments retained Passed; flattened arguments retained

    PR: 4/4 passed. Workaround: 3/4 passed. This resolves the four previously inconclusive checks as three passes and one observed workaround failure; it is not a claim that the original 3.8 matrix passed.

    The workaround collision trace is substantive rather than a service error:

    {"body":"filter","body_0":"{\"owner\": \"alice\", \"team\": \"red\"}"}

    The server received ?body=filter correctly, but its parsed JSON body was that string, not an object (43 wire bytes). The PR returned body_0 as {"owner":"alice","team":"red"} and the server received the expected flat object (30 bytes), with the same query parameter kept separate. Both tool calls returned {"ok":true}; the explicit argument/body-type assertion caught the workaround failure.

    I have retained that failed run rather than retrying it into a pass or coercing the value. This is one observed model output, not a measured failure rate or proof of deterministic failure. The allOf workaround should therefore be qualified beyond its existing requiredness limitation. The direct dictionary schema in the PR passed all four checks on this model.

    The checks stop at the real function response with skip_summarization; no final model summary is claimed. These remain synthetic localhost tests, not production API tests or a general guarantee of schema/value-constraint enforcement. No repository source code changed and the full unit-version matrix was not rerun for this follow-up.

  5. surajksharma07 commented on Nov 16, 2026

    @surajksharma07
    Collaborator

    Thanks @yang0228, that’s a really useful run, and keeping the failed collision trace was the right call. It shows the allOf workaround isn’t safe once a query param is also named body (Gemini sent body_0 as a JSON string). It also drops requiredness, so I’d only treat it as a stopgap for the plain case.

    Went through c07b76c and the split looks right. _is_dictionary_schema is shared by the parser and the sender, so a pure dict becomes one body arg sent whole via the deduped py_name, and named/mixed objects keep the flattened path.

    Current main (2.14.1) still drops the dict, so this is still needed. The branch merges cleanly, and e5ffe9c on main now serializes ApiParameter.required, so your requiredness carries through toolset serialization too.

    One behaviour change for reviewers: a bare type: object with no properties now gets an optional body arg instead of none. I’ve flagged #8038 for workflow approval and review (@xuanyang15).

  6. added
    tools
    on Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

tools

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions