Issue & Seemingly Effective Workaround: Gemini Mistakes Function Calling for Code Execution via Live API Voice Input

Hi everyone,

I wanted to report an issue I’ve encountered with Gemini regarding Function Calling when using voice input via the Live API. It seems that Gemini sometimes incorrectly interprets Function Calling requests as Code Execution, even when Code Execution is supposedly turned off.

I discovered that this problem appears to happen specifically when an example of the function call is included directly in the prompt, like function_defined_by_function_call(). Gemini seems to mistake this format for a request to execute code.

However, I found a workaround. If you format the example differently, for instance, like print(default_api.function_defined_by_function_call), Gemini seems to correctly understand it as Function Calling and behaves as expected.

I thought this information might be useful to others facing similar issues, so I wanted to share my findings.

Separately, I also believe the inability to explicitly disable Code Execution functionality is a concern that should perhaps be addressed.

Thanks.

Below is an example where it’s mistakenly treated as Code Execution (Note: Code Execution setting is off)

Example of successful Function Calling after adding default_api. to the code example (no other changes made):

1 Like

Having the same issue and unable to get it working in my application, it keeps doing executable_code=ExecutableCode(code="print(default_api.d… I tried the suggestion, but it will not work for me.

Anyone else got it working?

I can’t guarantee this will work, but based on my observations, there’s another condition besides the one already mentioned that seems to trigger the automatic generation of ExecutableCode.

It appears to happen if the names used for arguments, or for keys within objects defined in your function_calling setup, violate the standard Python variable naming rules. Specifically, valid Python identifiers should generally only contain letters (a-z, A-Z), numbers (0-9), and underscores (_), and they cannot start with a number.

If you’ve used names for your function arguments or the keys inside related objects that don’t adhere to these rules (e.g., using hyphens, special characters, or starting with a number), the system might incorrectly generate that ExecutableCode output and cause an error.

If your function_calling definition happens to use such non-compliant names, correcting them to follow standard Python naming conventions might resolve the issue. It might be worth checking.

1 Like