-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Labels
.NETIssue or Pull requests regarding .NET codeIssue or Pull requests regarding .NET codebugSomething isn't workingSomething isn't working
Description
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:
- Define a plugin method that accepts a class with a nullable string property
string? Location. - Register the plugin with Semantic Kernel
- Invoke a prompt using
GeminiPromptExecutionSettingswithToolCallBehavior = AutoInvokeKernelFunctions. - 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; }
}Metadata
Metadata
Assignees
Labels
.NETIssue or Pull requests regarding .NET codeIssue or Pull requests regarding .NET codebugSomething isn't workingSomething isn't working
Type
Projects
Status
Sprint: Done