You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
.Net: Bug: null argument for an optional value-type parameter throws instead of using the default value #14652
KernelFunctionFromMethod throws ArgumentOutOfRangeException when an argument value is null and the method parameter is a non-nullable value type with a default value, such as int count = 5. The default value is used only when the argument is missing, not when it is present with a null value.
This breaks function calling with FunctionChoiceBehaviorOptions.AllowStrictSchemaAdherence = true. In strict mode the OpenAI connector marks every parameter as required and adds "null" to the type of optional parameters (OpenAIFunction.ToFunctionDefinition). A model can then send null for an optional parameter it doesn't want to set. The connector stores that null in KernelArguments, and the function invocation fails, so the model gets an error result instead of the function output.
To reproduce
varfunction=KernelFunctionFactory.CreateFromMethod((intcount=5)=>count);// Throws ArgumentOutOfRangeException: Null object cannot be converted to a value type. (Parameter 'count')varresult=awaitfunction.InvokeAsync(newKernel(),new(){["count"]=null});
Based on the connector code, the same happens when a plugin method such as public string GetItems(string category, int limit = 10) is advertised with strict mode and the model calls it with {"category":"books","limit":null}. I reproduced it with the unit-level example above, not against a live model.
Expected behavior
The function runs with the parameter's default value (5 in the example above), the same as when the argument is omitted.
Activity