Is there a way to use structured outputs with arrays as root element ?
Issue
I want to parse collection of objects from textual data. So I need the model to return it as a collection to parse and use in list / array. Here’s how I’m using structured outputs in .NET SDK
var chatCompletionOptions = new ChatCompletionOptions
{
ResponseFormat = ChatResponseFormat.CreateJsonSchemaFormat(
jsonSchemaFormatName: $"{nameof(Employee)}s",
jsonSchemaFormatDescription: "Employees list",
jsonSchema: BinaryData.FromString(generator.Generate(typeof(Employee[])).ToString()))
};
When sending a prompt with these options, it fails from API side with exception :
HTTP 400 (invalid_request_error: )
Parameter: response_format
Invalid schema for response_format ‘Employees’: schema must be a JSON Schema of ‘type: “object”’, got ‘type: “array”’.
Is there a fix for this ?