Function calling schema inconsistencies between functionCallingConfig mode ANY and AUTO

When passing a tool schema with ANY nested map-like objects are not being returned properly. If I use AUTO, however, it works as expected.

Here’s an example call that does not return the correct function call. Switching mode to AUTO resolves the problem.

I’m not sure why this inconsistency exists. Am I doing something wrong? It seems like a bug in the API.

curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-lite:generateContent?key=$GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
      "systemInstruction": {
        "parts": [
          {"text": "You are a helpful assistant. Keep responses concise."}
        ]
      },
      "contents": [
        {
          "role": "user",
          "parts": [
            {
              "text": "FIll out a form with form id '\''jobApplication'\'' and entity references '\''person'\'' with keys '\''personId'\'' (12) and '\''personName'\'' (bob). YOU MUST FILL OUT THE KEYS"
            }
          ]
        }
      ],
      "tools": [
        {
          "functionDeclarations": [
            {
              "name": "fillFrom",
              "description": "Fill a form with data from specified entities. Be sure to provide all the required entities with their associated keys.",
              "parameters": {
                "type": "object",
                "properties": {
                  "formId": {
                    "type": "string",
                    "description": "The ID of the form to fill"
                  },
                  "entityReferences": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": ["entityName", "keys"],
                      "properties": {
                        "entityName": { "type": "string" },
                        "keys": {
                          "type": "object",
                          "minProperties": 1,
                          "maxProperties": 1
                        }
                      }
                    }
                  }
                },
                "required": ["formId", "entityReferences"]
              }
            }
          ]
        }
      ],
      "toolConfig": {
        "functionCallingConfig": {
          "mode": "ANY"
        }
      },
      "generationConfig": {
        "temperature": 0.3,
        "maxOutputTokens": 128
      }
  }'

@ihales,

welcome the the forum,

when you use ANY the model should pick from the fucnitons every time and it cannot give a generated response.

since AUTO is working ofr you , cabn you confirm your use case have no chance for a generic response i.e does the model have all the required information to fill the forum. please check if there is any chance that the model might want to ask clarifying questions or generate a geenerated response.

what output do you get when you use AUTO ? is it only a function call or any other text.

Thanks for the response.

My hope is to use ANY because I would like it to always give a tool request. In the example I provided, AUTO returns the following (showing candidates[0] from the response):

    {
      "content": {
        "parts": [
          {
            "functionCall": {
              "name": "fillFrom",
              "args": {
                "entityReferences": [
                  {
                    "keys": {
                      "personName": "bob",
                      "personId": 12
                    },
                    "entityName": "person"
                  }
                ],
                "formId": "jobApplication"
              }
            }
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0
    }

If I set mode to ANY, however I get this:

{
      "content": {
        "parts": [
          {
            "functionCall": {
              "name": "fillFrom",
              "args": {
                "entityReferences": [
                  {
                    "entityName": "person",
                    "keys": {}
                  }
                ],
                "formId": "jobApplication"
              }
            }
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0
    }

You’ll notice that the response includes only a function call, and the different modes have different values under content.parts[0].functionCall.args.entityReferences.keys. I have never seen those keys populated out when mode is ANY, and they are always populated when mode is AUTO.

Any insight into why this would be happening?

Hi @ihales,
This happens because ANY mode forces strict execution based solely on the defined schema, skipping the reasoning step AUTO uses to infer dynamic structures. Since your keys parameter was defined as a generic object without specific properties, the model returned an empty {} to satisfy the type requirement safely rather than guessing the structure.

To fix this, replace the generic Map (Object) with a concrete List of Key-Value pairs. Here is the corrected parameters section of your tool definition:

"parameters": {
"type": "object",
"properties": {
"formId": { "type": "string" },
"entityReferences": {
"type": "array",
"items": {
"type": "object",
"required": ["entityName", "attributes"],
"properties": {
"entityName": { "type": "string" },
"attributes": {
"type": "array",
"description": "List of key-value pairs for the entity",
"items": {
"type": "object",
"properties": {
"key": { "type": "string" },
"value": { "type": "string" }
}
}
}
}
}
}
},
"required": ["formId", "entityReferences"]
}