-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
Describe the bug
When a class with an array of objects that contain nullable property (e.g. string? City) 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).
This is a similar situation that has been resolved in ticket #11675 but this time it's not top level properties but nested in an array
To Reproduce
Steps to reproduce the behavior:
- Define a plugin method that accepts a class with an array of objects that have nullable string property string? City.
- Register the plugin with Semantic Kernel
- Invoke a prompt using GeminiPromptExecutionSettings with ToolCallBehavior = AutoInvokeKernelFunctions.
- Observe that the Gemini API returns a 400 error.
"tools": [
{
"functionDeclarations": [
{
"description": "Get the weather for a given location.",
"name": "MyWeatherPlugin_GetWeather",
"parameters": {
"properties": {
"request": {
"properties": {
"Locations": {
"items": {
"properties": {
"City": {
"type": [
"string",
"null"
]
},
"Country": {
"type": [
"string",
"null"
]
}
},
"type": "object"
},
"nullable": true,
"type": "array"
}
},
"type": "object"
}
},
"required": [
"request"
],
"type": "object"
}
}
]
}
]
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.60.0-alpha
AI model: Gemini-2.5-flash
IDE: All
OS: Windows
Additional context
public class WeatherLocation
{
public string? City { get; set; }
public string? Country { get; set; }
}
public sealed class WeatherRequest
{
public WeatherLocation[]? Locations { get; set; }
}
public class MyWeatherPlugin
{
[KernelFunction]
[Description("Get the weather for a given location.")]
private string GetWeather(WeatherRequest request)
{
return $"The weather in {request?.Locations.First().City} is sunny.";
}
}
Metadata
Metadata
Assignees
Labels
Type
Projects
Status