Skip to content
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

.Net: Bug: .NET - Structured Output ResponseFormat schema incorrect for arrays of repeated types --- Invalid schema for response_format - reference can only point to definitions defined at the top level of the schema. #10142

Open
AaronMacF opened this issue Jan 9, 2025 · 0 comments
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code triage

Comments

@AaronMacF
Copy link

Describe the bug
When using ResponseFormat = typeof(MyClass), the schema is incorrectly generated when two array properties use the same object type, leading to the following error:

{
  "error": {
    "message": "Invalid schema for response_format 'MyClass': In context=('properties', 'PropertyB', 'items'), reference can only point to definitions defined at the top level of the schema.",
    "type": "invalid_request_error",
    "param": "response_format",
    "code": null
  }
}

To Reproduce
Steps to reproduce the behavior:

See this MRE:

Program.cs

OpenAIPromptExecutionSettings executionSettings = new() { ResponseFormat = typeof(MyClass) };
 KernelArguments kernelArgs = new(executionSettings);
await kernel.InvokeAsync("PluginName", "FunctionName", kernelArgs);

MyClass.cs

public class MyClass
{
  public SubClass[] PropertyA { get; set; }
  public SubClass[] PropertyB { get; set; }
}

SubClass.cs

public class SubClass
{
  public string Property1 { get; set; }
  public int Property2 { get; set; }
}

Invalid generated schema:

{
  "response_format": {
    "json_schema": {
      "name": "MyClass",
      "schema": {
        "type": "object",
        "properties": {
          "PropertyA": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "Property1": { "type": "string" },
                "Property2": { "type": "integer" }
              },
              "additionalProperties": false,
              "required": ["Property1", "Property2"]
            }
          },
          "PropertyB": {
            "type": "array",
            "items": { "$ref": "#/properties/PropertyA/items" }
          }
        },
        "additionalProperties": false,
        "required": ["PropertyA", "PropertyB"]
      },
      "strict": true
    },
    "type": "json_schema"
  }
}

Expected valid schema

{
  "response_format": {
    "json_schema": {
      "name": "MyClass",
      "schema": {
        "type": "object",
        "properties": {
          "PropertyA": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "Property1": { "type": "string" },
                "Property2": { "type": "integer" }
              },
              "additionalProperties": false,
              "required": ["Property1", "Property2"]
            }
          },
          "PropertyB": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "Property1": { "type": "string" },
                "Property2": { "type": "integer" }
              },
              "additionalProperties": false,
              "required": ["Property1", "Property2"]
            }
          }
        },
        "additionalProperties": false,
        "required": ["PropertyA", "PropertyB"]
      },
      "strict": true
    },
    "type": "json_schema"
  }
}

Expected behavior
The generated schema is valid, and PropertyB doesn't use a reference to PropertyA

Platform

  • Language: C#
  • Source: Semantic Kernel version 1.33.0
@AaronMacF AaronMacF added the bug Something isn't working label Jan 9, 2025
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels Jan 9, 2025
@github-actions github-actions bot changed the title Bug: .NET - Structured Output ResponseFormat schema incorrect for arrays of repeated types --- Invalid schema for response_format - reference can only point to definitions defined at the top level of the schema. .Net: Bug: .NET - Structured Output ResponseFormat schema incorrect for arrays of repeated types --- Invalid schema for response_format - reference can only point to definitions defined at the top level of the schema. Jan 9, 2025
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 triage
Projects
None yet
Development

No branches or pull requests

2 participants