Gemini doesn't accept parameterless functions

Hello,

It seems I can not pass parameterless functions to Gemini. Error is as bad as usual: “Request contains an invalid argument.”.

  {
    "type":"function",
    "function": {
      "name": "get_current_time",
      "description": "Get current date and time in 'yyyy-MM-dd HH:mm:ss' format. It also returns current time zone in GMT form",
      "parameters": {
        "type": "object",
        "properties": {
        }
      }
    }
  }

If I provide a fake property it accepts the function.

  {
    "type":"function",
    "function": {
      "name": "get_current_time",
      "description": "Get current date and time in 'yyyy-MM-dd HH:mm:ss' format. It also returns current time zone in GMT form",
      "parameters": {
        "type": "object",
        "properties": {
          "none": {
            "type": "string",
            "description": "Fake property"
          }
        }
      }
    }
  }

If I get rid of parameters - it fails anyway:

  {
    "type":"function",
    "function": {
      "name": "get_current_time",
      "description": "Get current date and time in 'yyyy-MM-dd HH:mm:ss' format. It also returns current time zone in GMT form",
    }
  }
1 Like

Hey @Gregory_Ledenev , could you try passing the parameterless function using the format below?

tools = {
    "function_declarations": [
      {
        "name": "get_current_time",
        "description": "Get current date and time in 'yyyy-MM-dd HH:mm:ss' format.",
      }
    ]
}

response = model.generate_content("What time is it right now?",tools=tools)
response

Hello,

Thank you for your reply.

Tried. Got even worse response.

REQUEST:

{
  "model" : "gemini-1.5-flash",
  "messages" : [{"content":"what time is it","role":"user"}],
  "tools": {
	"function_declarations": [{"name":"get_current_time","description":"Get current date and time in 'yyyy-MM-dd HH:mm:ss' format."}]
}, 
 	
}

RESPONSE:

[{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"function_declarations\" at 'tools': Cannot find field.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "tools",
            "description": "Invalid JSON payload received. Unknown name \"function_declarations\" at 'tools': Cannot find field."
          }
        ]
      }
    ]
  }
}
]

Original format (compatible with OpenAI and xAI) works well. There’re only troubles with parameterless functions.

I tested it on my side, and it seems to be working. Here’s the link to the Colab gist:

Colab_Notebook

You guys are not on the same page. Gregory is using flash, and you are proving that pro works.

I tried with both the model and its working fine.

1 Like

To be on the same page: please find below a curl call:

curl "https://generativelanguage.googleapis.com/v1beta/chat/completions?key=YOUR_KEY" \
    -H 'Content-Type: application/json' \
    -X POST \
    -d '{
          "model" : "gemini-1.5-flash",
          "messages" : [{"content":"what time is it","role":"user"}],
          "tools":[{"type":"function","function":{"name":"get_current_time","description":"Get current date and time. It also returns current time zone in GMT form"}}]
        }'

and a responce:

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

Got it. The issue happens when we try to pass a parameterless function using the OpenAI libraries with the Gemini API.

Thanks @Gregory_Ledenev , I have escalated this with the team.

2 Likes

Thank you very much. Appreciated it!

Can you also check this issue too? I can’t return back function calls results to Gemini…

1 Like

Hi, any ETA on the fix for this?

@GUNAND_MAYANGLAMBAM

FYI, this problem also exists when using using the google.generativeai library. For instance, when I pass this tool definition to the api

{
        "name": "get_state",
        "description": "Function to get the current state, as defined in <state>",
        "parameters": {
            "properties": {},
            "type": "object"
        }
    }

i get the following error

    raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.InvalidArgument: 400 * GenerateContentRequest.tools[0].function_declarations[4].parameters.properties: should be non-empty for OBJECT type

So I believe this is a server-side issue. It has nothing to do with openai library compatibility

Hi @GUNAND_MAYANGLAMBAM,

Any update on this issue please? I’ve been blocked by this for a while now, any info would be appreciated.

Thanks!

Hey @vaeho , the issue has already been fixed. You should be able to pass a parameterless function now, similar to the request below:

curl "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer GEMINI_API_KEY" \
-d '{
  "model": "gemini-1.5-pro",
  "messages": [
    {
      "role": "user",
      "content": "What'\''s the weather like in Chicago today?"
    }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get the current weather in a given location"

      }
    }
  ]
}'

@GUNAND_MAYANGLAMBAM Still doesn’t seem to be working. The example you provided isn’t really the same. What I am trying to do is define an object but not provide any predefined properties. The properties of the params object aren’t known in advance they are determined by the LLM at inference time so I want it to fill out parameters by itself.

I am trying this with gemini-2.0-flash-exp. Other LLM providers are handling this completely fine.

{
    "type": "function",
    "function": {
        "name": "execute_operation",
        "description": "Execute an operation",
        "parameters": {
            "type": "object",
            "properties": {
                "operation": {
                    "type": "string",
                    "description": "Name of the operation to execute"
                },
                "target": {
                    "type": "string",
                    "description": "Target of the operation"
                },
                "params": {
                    "type": "object",
                    "description": "Parameters for the operation"
                }
            },
            "required": ["operation", "target", "params"]
        }
    }
}

This is the error that I am getting:

BadRequestError: Error code: 400 - [{'error': {'code': 400, 'message': '* GenerateContentRequest.tools[0].function_declarations[0].parameters.properties[params].properties: should be non-empty for OBJECT type\n', 'status': 'INVALID_ARGUMENT'}}]

I still got error

  "error": {
    "code": 400,
    "message": "* GenerateContentRequest.tools[0].function_declarations[0].parameters.properties: should be non-empty for OBJECT type\n",
    "status": "INVALID_ARGUMENT"
  }
}

for this request

curl -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-001:generateContent?key=${GEMINI_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Select a tool to print hi"
        }
      ]
    }
  ],
  "tools": [
    {
      "function_declarations": [
        {
          "name": "print_hi",
          "description": "Print hi.",
          "parameters": {
            "type": "object",
            "properties": {},
            "required": []
          }
        }
      ]
    }
  ],
  "toolConfig": {
    "functionCallingConfig": {
      "mode": "ANY"
    }
  },
  "generationConfig": {}
}'