Gemini Live API unexpectedly invokes execute_code and other built in tools even when not configured

I’m running into a reproducible issue with the Gemini Live API where the execute_code tool is being invoked, even though it’s not included in my tools configuration.

Here’s a simplified version of my setup:

tools = [{
    "function_declarations": [
        {
            "name": "get_candidate_code",
            "description": "Gets the candidate's code",
            "parameters": {"type": "object", "properties": {}}
        },
        {
            "name": "check_conversation_context",
            "description": "Analyze conversation context",
            "parameters": {
                "type": "object",
                "properties": {
                    "context_type": {
                        "type": "string",
                        "enum": ["candidate_intent", "stuck_indicators"]
                    }
                }
            }
        }
    ]
}]

session_config = {
    "tools": tools,
    "system_instruction": {"parts": [{"text": system_prompt}]},
    "response_modalities": ["AUDIO"],
    "speech_config": {"voice_config": {"prebuilt_voice_config": {"voice_name": "Puck"}}},
    "generation_config": {"temperature": 0.8}
}

Despite not adding execute_code, the model still tries to invoke it in some cases (e.g., when user input resembles a coding task). This is unexpected because the assumption is that only the tools explicitly listed would be available to the model.

If this is intended behavior, it should be documented more clearly. Otherwise, it might be an oversight in how the tool permissions are enforced internally. Also there should be an option to explicitly disable some internal tools as other APIs provide through tool_config

Would appreciate clarity on:

  • Whether execute_code is implicitly enabled,
  • If there’s a way to fully restrict the model to only declared tools,
  • And whether a fix or workaround exists.

Let me know if a minimal reproducible example would help — happy to provide one.

1 Like

Hello and welcome to the Forum!

To help us look into this, could you please share the exact query you sent and the response you received when execute_code was unexpectedly called even though it was not set up in your tools?

I have exact same issue, it try to run code execution when I only include tool call in my config (Without { "code_execution": {} }). It is so bad because when it does and it fail to execute code, the live api will say something like sorry some problems occurs while it should do a tool call instead.

@Swati_Ahuja @Bik weere you able to find a solution to resolve this issue. I am encountering the same eventhough function call is completed the codeexecution result throws a parsing error.