DocsGPT icon indicating copy to clipboard operation
DocsGPT copied to clipboard

🐛 Bug Report: Gemini tool declarations lose the fields of nested object parameters

Open cr-sbarbouche opened this issue 1 month ago • 2 comments

📜 Description

GoogleLLM._clean_schema (docsgpt/llm/google_ai.py) recurses into every dict value of a schema, including the properties map, and runs its keyword filter on it. The keys of properties are the tool author's field names, not schema keywords, so any nested field that isn't called type, description, items, properties, required, enum, pattern, minimum, maximum, nullable or default is dropped. The nested required list goes with them, because it is checked against the now empty properties. Top-level parameters are spared because _clean_tools_format walks those itself. A parameter that is an object, or a list of objects, therefore reaches Gemini as an object with no fields, and the model is never told what to put in it. ToolExecutor._build_tool_parameters keeps nested properties and required on purpose, so MCP tools, imported API actions and client tools can all send these schemas. The existing tests only use a property literally named type, and one of them says "Property names must be in allowed_fields to survive _clean_schema", so the quirk was noticed but never fixed.

👟 Reproduction steps

  1. Give a Gemini agent a tool with an object or array-of-objects parameter (any MCP tool that takes a list of items will do).
  2. Look at the function declaration that is sent to Gemini. The same thing without the UI:
repro.py
import json

from docsgpt.llm.google_ai import GoogleLLM

tool = {
    "type": "function",
    "function": {
        "name": "create_events",
        "description": "Add events to a calendar",
        "parameters": {
            "type": "object",
            "properties": {
                "events": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {"title": {"type": "string"}, "start": {"type": "string"}},
                        "required": ["title"],
                    },
                },
                "options": {"type": "object", "properties": {"notify": {"type": "boolean"}}},
            },
            "required": ["events"],
        },
    },
}

llm = GoogleLLM.__new__(GoogleLLM)
declaration = llm._clean_tools_format([tool])[0].function_declarations[0]
print(json.dumps(declaration.parameters.model_dump(exclude_none=True, mode="json")))

👍 Expected behavior

events.items keeps title and start plus its required: ["title"], and options keeps notify.

👎 Actual Behavior with Screenshots

On main the script prints:

{"properties": {"events": {"items": {"properties": {}, "type": "OBJECT"}, "type": "ARRAY"}, "options": {"properties": {}, "type": "OBJECT"}}, "required": ["events"], "type": "OBJECT"}

title, start, notify and the nested required are gone.

💻 Operating system

MacOS

🤖 What development environment are you experiencing this bug on?

Local dev server

📃 Provide any additional context for the Bug.

The output above is the declaration built from the real google-genai types; I haven't sent it to the live Gemini API. A type given as a list (["string", "null"]) or a non-string enum also fails in _clean_schema, as a pydantic validation error when the tool is built. That is a separate problem and not part of this issue.

🔗 Are you willing to submit PR?

Yes, a PR is coming.

cr-sbarbouche avatar Oct 30 '26 09:10 cr-sbarbouche

Please finish your two open assigned issues here before taking another one. This issue remains unassigned for now.

Automated triage. A maintainer will follow up.

arc53-machine avatar Oct 30 '26 09:10 arc53-machine

Hi @cr-sbarbouche, I'm interested in contributing to this issue. I noticed you mentioned that a PR is coming. Are you already working on the fix, or would you be open to collaborating on the implementation or regression tests?

Thanks!

Shivam040 avatar Nov 04 '26 17:11 Shivam040