Skip to content

.Net: Bug: Function call with complex objects fails with o3-mini #11509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AlesRuzickaEu opened this issue Apr 11, 2025 · 3 comments
Open

.Net: Bug: Function call with complex objects fails with o3-mini #11509

AlesRuzickaEu opened this issue Apr 11, 2025 · 3 comments
Assignees
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code

Comments

@AlesRuzickaEu
Copy link

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.

@AlesRuzickaEu AlesRuzickaEu added the bug Something isn't working label Apr 11, 2025
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels Apr 11, 2025
@github-actions github-actions bot 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
@SergeyMenshykh
Copy link
Member

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:

{
  "type": "object",
  "required": [
    "result"
  ],
  "properties": {
    "result": {
      "type": "object",
      "properties": {
        "Name": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "Name"
      ]
    }
  },
  "additionalProperties": false
}

So, at the moment, you have two options:

  1. Change the model to a different one that supports the structured output and does not fail when it's enabled.
  2. Disable the strict mode:
    FunctionChoiceBehavior = FunctionChoiceBehavior.Required(options: new FunctionChoiceBehaviorOptions { AllowStrictSchemaAdherence = false })
    or just
    FunctionChoiceBehavior = FunctionChoiceBehavior.Required()

@SergeyMenshykh SergeyMenshykh moved this from Bug to Sprint: In Progress in Semantic Kernel Apr 14, 2025
@SergeyMenshykh SergeyMenshykh moved this from Sprint: In Progress to Sprint: In Review in Semantic Kernel Apr 14, 2025
@AlesRuzickaEu
Copy link
Author

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.

@SergeyMenshykh
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code
Projects
Status: Sprint: In Review
Development

No branches or pull requests

4 participants