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
Describe the bug
Function call with complex object and optional values fail with o3-mini (works with gpt-4o)
To Reproduce
Minimal code:
var builder = Kernel
.CreateBuilder();
builder.AddOpenAIChatCompletion("o3-mini", apiKey);
var kernel = builder.Build();
kernel.Plugins.AddFromType<Plugin>("Plugin");
var chatCompletionServices = kernel.GetRequiredService<IChatCompletionService>();
var promptExecutionSettings = new OpenAIPromptExecutionSettings
{
FunctionChoiceBehavior = FunctionChoiceBehavior.Required(options: new FunctionChoiceBehaviorOptions
{
AllowStrictSchemaAdherence = true,
})
};
var history = new ChatHistory();
history.AddUserMessage("Generate name as 'a'");
var result = await chatCompletionServices.GetChatMessageContentAsync(history, promptExecutionSettings, kernel);
class Plugin
{
[KernelFunction("generate")]
public void Generate(Result result)
{
}
}
public class Result
{
public string? Name { get; set; }
}
Expected behavior
Expect function call with complex object
Actual behavior
Throws Error:
Microsoft.SemanticKernel.HttpOperationException: 'HTTP 400 (invalid_request_error: )
Invalid schema for function 'Plugin-generate': In context=('properties', 'result', 'properties', 'Name'), schema must have a 'type' key.'
Platform
Language: C#
Source: NuGet package version 1.45.0
AI model: OpenAI:o3-mini
IDE: Visual Studio
OS: Windows
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered:
github-actionsbot
changed the title
Bug: Function call with complex objects fails with o3-mini
.Net: Bug: Function call with complex objects fails with o3-mini
Apr 11, 2025
Hi @AlesRuzickaEu, for some reason "o3-mini" fails when the strict mode is enabled, even though a few other models that support the strict mode work perfectly fine. The produced schema for the function parameters is fully compatible with the one required by the strict mode:
Change the model to a different one that supports the structured output and does not fail when it's enabled.
Disable the strict mode: FunctionChoiceBehavior = FunctionChoiceBehavior.Required(options: new FunctionChoiceBehaviorOptions { AllowStrictSchemaAdherence = false })
or just FunctionChoiceBehavior = FunctionChoiceBehavior.Required()
What worked for me is making everything required.
Then it works fine even with strict mode.
There seems to be some issue with "null" options.
I just wondered if there is not other way here, maybe some change in definition.
Yep, making the Result.Name not nullable worked for me as well. I saw a few posts on the internet where people complain about the same issue. It may be worth opening an issue/thread on the OpenAI dev forum.
Describe the bug
Function call with complex object and optional values fail with o3-mini (works with gpt-4o)
To Reproduce
Minimal code:
Expected behavior
Expect function call with complex object
Actual behavior
Throws Error:
Microsoft.SemanticKernel.HttpOperationException: 'HTTP 400 (invalid_request_error: )
Invalid schema for function 'Plugin-generate': In context=('properties', 'result', 'properties', 'Name'), schema must have a 'type' key.'
Platform
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: