Is it possible to set a type that enforces GPT to return the output in that format with function calls?

I have the following function call:

{
“name”: “set_absolute_parameter_values_for_component”,
“example”: “Change the margin to ‘comfortable’.”,
“description”: "Set specific values for parameters of a single component in the specified card(s). "+
“This function applies absolute changes. Note: the ‘Content’ component cannot contain text, but ‘Info’ can hold text.”+
“Call this function if both a relative and an absolute term are used.”,
“parameters”: {
“type”: “object”,
“properties”: {
“to_card_list”: {
“type”: “string”,
“description”: "A list with card names that the user wants to update. If ",
“enum” : CARD_INFO[‘cards’],
},
“component_list”: {
“type”: “string”,
“description”: “A list with the component that the user wants to update. Note: the ‘Content’ component can NOT contain text.”,
“enum” : CARD_INFO[‘component_list’],
},
“parameter_dict”: {
“type”: “string”,
“description”: “A dictionary mapping parameters to their desired values.”,
“enum” : list(CARD_INFO[‘all_parameters’]),
},
}
}
},

As the names for the parameters suggest, I want to get two lists and a dictionary. Sometimes ChatGPT (both 3.5 turbo and 4) returns the correct format, whereas it returns the wrong format too sometimes. I get an error when I change the types to ‘list’ and ‘dict’. Based on suggestions, I tries changing it to ‘array’ and ‘object’ too, which also resulted in errors.

Is it possible to set the type to lists and dicts?

The JSON equivalent for a python list is an array. Specifying an array datatype will allow return of multiple list elements if that is what the AI wants to create.

The only data type that will take OpenAI’s “enum” (taken from typescript and placed in json awkwardly) is a string.

An “example” is not seen by the AI.

Thanks, that is very helpful! Is it also possible to request a dictionary in JSON?

JSON is very like a python dictionary, and the AI has lots of training on python. So much that if you are using a boolean type, you should check the capitalization of “True” before you let a json library fail on it. You also can simply state in the property description that the data is a python list with dictionaries, being run by python API code, or whatever is needed to make your function understood.