Skip to content

HTTP 400 error "Invalid 'response_format.json_schema.name'" when generic type is used for ResponseFormat #9416

Closed

Description

Describe the bug
OpenAI API fails with error if generic type is used for ResponseFormat:

HTTP 400 (invalid_request_error: invalid_value)
Parameter: response_format.json_schema.name

Invalid 'response_format.json_schema.name': string does not match pattern. Expected a string that matches the pattern '^[a-zA-Z0-9_-]+$'.

To Reproduce
Use any generic type as ResponseFormat. For example:

public class Cart<T>
{
   public decimal Total { get; set; }
   public List<T> LineItems { get; set; }
}

public class LineItem 
{
   public class ProductName { get; set; }
   public int Quantity { get; set; }
}

Expected behavior
This issue is caused by use of GetType().Name at

return ChatResponseFormat.CreateJsonSchemaFormat(type.Name, schemaBinaryData, jsonSchemaIsStrict: true);

which results into Cart`1 json schema name with ` symbol, while OpenAI API allows only alphanumberic values and _ or - symbols.

Platform

  • Language: C#
  • Source: dotnet-1.25.0

Activity

  1. changed the title [-]Bug:[/-] [+].Net: Bug:[/+] on Oct 24, 2024
  2. changed the title [-].Net: Bug:[/-] [+]HTTP 400 error "Invalid 'response_format.json_schema.name'" when generic type is used for ResponseFormat[/+] on Oct 24, 2024
  3. evchaki commented on Oct 31, 2024

    @evchaki
    Contributor

    Aleksandr Vishniakov (@asvishnyakov) - thanks for reporting this. We have a PR open to fix this you can check out #9490

  4. moved this from Sprint: In Review to Sprint: Done in Semantic Kernelon Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

.NETIssue or Pull requests regarding .NET codebugSomething isn't working

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions