Skip to content

.Net: Bug: Gemini LLM returns 400 error when plugin input class contains nullable properties #11675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
m-soltys opened this issue Apr 22, 2025 · 0 comments
Assignees
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code

Comments

@m-soltys
Copy link

Describe the bug
When a class with a nullable property (e.g. string? Location) is used as an input parameter to a plugin method in a Gemini LLM function call, a 400 error is returned from the Gemini API. This error does not occur when the same property is defined as non-nullable (string Location).

To Reproduce
Steps to reproduce the behavior:

  1. Define a plugin method that accepts a class with a nullable string property string? Location.
  2. Register the plugin with Semantic Kernel
  3. Invoke a prompt using GeminiPromptExecutionSettings with ToolCallBehavior = AutoInvokeKernelFunctions.
  4. Observe that the Gemini API returns a 400 error.
{
  "name": "Plugin_GetWeather",
  "description": "Get the weather for a given location.",
  "parameters": {
    "type": "object",
    "required": ["request"],
    "properties": {
      "request": {
        "type": "object",
        "properties": {
          "Location": {
            "type": ["string", "null"]
          }
        }
      }
    }
  }
}

Expected behavior
The function should be successfully invoked, and Gemini should handle nullable fields in the schema without returning an error.
The issue is caused by the type definition "type": ["string", "null"]

Screenshots
N/A

Platform

  • Language: C#
  • Source: Microsoft.SemanticKernel 1.47, Microsoft.SemanticKernel.Connectors.Google 1.47.0-alpha
  • AI model: Gemini-2.0-flash
  • IDE: All
  • OS: Windows

Additional context

var kernelBuilder = Kernel.CreateBuilder()
    .AddGoogleAIGeminiChatCompletion(
        modelId: "gemini-2.0-flash",
        apiKey: apiKey);

kernelBuilder.Plugins.AddFromType<Plugin>();

var promptExecutionSettings = new GeminiPromptExecutionSettings()
{
    ToolCallBehavior = GeminiToolCallBehavior.AutoInvokeKernelFunctions,
};

var kernel = kernelBuilder
    .Build();

var response = await kernel.InvokePromptAsync("Hi, what's the weather in New York?", new(promptExecutionSettings));

Console.WriteLine(response.ToString());

class Plugin
{
    [KernelFunction]
    [Description("Get the weather for a given location.")]
    string GetWeather(Request request)
    {
        return $"The weather in {request?.Location} is sunny.";
    }
}

class Request
{
    public string? Location { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code
Projects
Status: Bug
Development

No branches or pull requests

3 participants