#Is it possible to replace enum with oneOf in the structured outputs json schema

1 messages · Page 1 of 1 (latest)

rich compass
#

Is it possible to replace enum with oneOf in the structured outputs json schema?

For example so it would look like this:

level_1_schema = {
"name": "level_1_category_identification",
"schema": {
"type": "object",
"properties": {
"entities": {
"type": "array",
"items": {
"type": "object",
"properties": {
"level_1_category": {
"type": "string",
"description": "The category into which the effect of the detail in question falls",
"oneOf": [
{
"const": "type1",
"description": "Description of type1."
},
{
"const": "type2",
"description": "Description of type2"
},
{
"const": "type3",
"description": "Description of type3"
}
]
}
},
"required": [
"level_1_category"
],
"additionalProperties": False
}
}
},
"required": [
"entities"
],
"additionalProperties": False,
"strict": True
}
}

icy nightBOT
#

Hi @rich compass. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in the knowledge sources, it seems that the oneOf keyword is supported in the Structured Outputs feature of OpenAI's API. However, it's important to note that the root level object of a schema must be an object, and not use oneOf source (https://platform.openai.com/docs/guides/structured-outputs/root-objects-must-not-be-anyof).

In your example, you are using oneOf within the properties of an object, not at the root level, so it should be acceptable. However, the oneOf keyword is used with an array of schemas, and each schema in the array can be of any type. In your case, you are using const which is not mentioned in the supported types for Structured Outputs. The supported types are String, Number, Boolean, Integer, Object, Array, Enum, and anyOf source (https://platform.openai.com/docs/guides/structured-outputs/supported-schemas).

Therefore, while you can use oneOf, the use of const might not be supported. It would be best to refer to the official OpenAI documentation or contact OpenAI support for the most accurate information.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@rich compass kapa.ai is still learning and improving, please let us know how it did by reacting below

rich compass
#

@icy night There seems to be some confusion - the documentation only talks about anyOf, whereas I would like to use oneOf - are you sure oneOf is really supported?

icy nightBOT
#

Let me check the knowledge base for you. One moment! :books:

#

I apologize for the confusion. Based on the provided knowledge sources, the oneOf keyword is not explicitly mentioned as a supported type for Structured Outputs in OpenAI's API. The supported types listed are String, Number, Boolean, Integer, Object, Array, Enum, and anyOf source (https://platform.openai.com/docs/guides/structured-outputs/supported-schemas).

Therefore, it's not clear from the provided sources whether oneOf is supported. For the most accurate information, it would be best to refer to the official OpenAI documentation or contact OpenAI support.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: