Skip to content

.Net: Bug: Gemini LLM returns 400 error when plugin input class contains objects (in an nullable array/list) that contain nullable properties (similar to #11675) #12743

@JoschaMetze

Description

@JoschaMetze

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:

  1. Define a plugin method that accepts a class with an array of objects that have nullable string property string? City.
  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.
"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

.NETIssue or Pull requests regarding .NET codeai connectorAnything related to AI connectorsbugSomething isn't working

Type

Projects

Status

Bug

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions