Bug - seeing Request contains an invalid argument when using tool calling

Here’s the error I see

 "error": {
E                               "code": 400,
E                               "message": "Request contains an invalid argument.",
E                               "status": "INVALID_ARGUMENT"
E                             }
E                           }

Here’s the request I sent to AI studio

curl -X POST \
https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=AI*********** \
-H 'Content-Type: *****' \
-d '{'contents': [{'role': 'user', 'parts': [{'text': "What's the weather like in Boston today in Fahrenheit?"}]}], 'tools': [{'function_declarations': [{'name': 'get_current_weather', 'description': 'Get the current weather in a given location', 'parameters': {'type': 'object', 'properties': {'location': {'type': 'string', 'description': 'The city and state, e.g. San Francisco, CA'}, 'unit': {'type': 'string', 'enum': ['celsius', 'fahrenheit']}}, 'required': ['location']}}]}], 'toolConfig': {'functionCallingConfig': {'mode': 'ANY', 'allowed_function_names': ['get_current_weather']}}}'

Welcome to the forums!

Two things jump out as somewhat confusing to me that could be the cause of your issues:

  • Is the content type deliberately masked out?
  • The data being sent is in single quotes, but you are also using single quotes for strings in the JSON. So what may be happening is that you are closing the string and having extra characters. I’m not sure what is actually being sent.

I just had the same error, and it works if I remove “enum”. Strange that this was working only a few weeks ago…

Try adding the “format” property. There is a obscure example in the schema docs. Like so:

{
  "function_declarations": [
    {
      "name": "get_current_weather",
      "description": "Get the current weather in a given location",
      "parameters": {
        "type": "object",
        "properties": {
          "location": {
            "type": "string",
            "description": "The city and state, e.g. San Francisco, CA"
          },
          "unit": {
            "type": "string",
            "format": "enum",
            "enum": ["celsius", "fahrenheit"]
          }
        },
        "required": ["location"]
      }
    }
  ]
}
1 Like