oneOf, allOf Usage has problems with strict mode

Basically as the header suggests, I have problems using oneOf with strict: True option.

Without using strict, API accepts the requests with oneOf, allOf parameters defined as such for example:

            "oneOf": [
              {
                "required": ["operator", "operands"]
              },
              {
                "required": ["operator", "operand"]
              },
              {
                "required": ["operator", "expression"]
              }
            ]

However when I enable strict mode on, following error throws:

BadRequestError: Error code: 400 - {‘error’: {‘message’: “Invalid schema for function ‘create_where_clause’: In context=(), ‘oneOf’ is not permitted.”, ‘type’: ‘invalid_request_error’, ‘param’: ‘tools[0].function.parameters’, ‘code’: ‘invalid_function_parameters’}}

Hi @yitopeligo !

Basically OpenAI structured outputs doesn’t currently support oneOf, so you would need to use anyOf instead.

The reason why you get an error in “strict” mode is because in strict mode, a more thorough validation against their JSON Schema Spec support is performed. OpenAI supports only a subset of JSON Schema Spec.

1 Like

Hey @platypus @yitopeligo

Does this mean I can use anyOf in strict: true? Or is there no option to use them at all if strict: true?

Hi @wolsen ! You can use anyOf in strict mode, yes.

1 Like

An example of an anyOf schema - the alternate schema gives the AI a place to write a non-response, for example, that it doesn’t have enough info to fill out the main schema.

{
   "name":"my_response",
   "strict":true,
   "schema":{
      "type":"object",
      "properties":{
         "my_response":{
            "anyOf":[
               {
                  "type":"object",
                  "properties":{
                     "company_product_search":{
                        "type":"string"
                     }
                  },
                  "required":[
                     "company_product_search"
                  ],
                  "additionalProperties":false
               },
               {
                  "type":"object",
                  "properties":{
                     "no_response_reason":{
                        "type":"string",
                        "enum":[
                           "not_parts_request",
                           "question_unclear",
                           "not_company_scope",
                           "policy_violation"
                        ]
                     }
                  },
                  "required":[
                     "no_response_reason"
                  ],
                  "additionalProperties":false
               }
            ],
            "additionalProperties":false
         }
      },
      "required":[
         "my_response"
      ],
      "additionalProperties":false
   }
}

They need to be different named schemas within, and the anyOf has to be within a root object; you can’t use it like an overload.

1 Like