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

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

Open
asvishnyakov opened this issue Oct 24, 2024 · 1 comment · May be fixed by #9490
Assignees
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code

Comments

@asvishnyakov
Copy link

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
@asvishnyakov asvishnyakov added the bug Something isn't working label Oct 24, 2024
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels Oct 24, 2024
@github-actions github-actions bot changed the title Bug: .Net: Bug: Oct 24, 2024
@asvishnyakov asvishnyakov changed the title .Net: Bug: HTTP 400 error "Invalid 'response_format.json_schema.name'" when generic type is used for ResponseFormat Oct 24, 2024
@evchaki
Copy link
Contributor

evchaki commented Oct 31, 2024

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

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

Successfully merging a pull request may close this issue.

4 participants