In assistant api function calling, how to specify the structure of the output from external function?

Here’s an example on how to use assistant api ( cookbook . openai. com / examples / assistants_api_overview_python ). In the example, we need to specify the structure of the input for the external function display_quiz in function_json. How can we specify the structure of the output from display_quiz? In the example, its output is a list of string. But if its output is a list of str , for example, it’s a list of lists, do we need to specify it or llm can recognize it without any specification?

function_json = {
    "name": "display_quiz",
    "description": "Displays a quiz to the student, and returns the student's response. A single quiz can have multiple questions.",
    "parameters": {
        "type": "object",
        "properties": {
            "title": {"type": "string"},
            "questions": {
                "type": "array",
                "description": "An array of questions, each with a title and potentially options (if multiple choice).",
                "items": {
                    "type": "object",
                    "properties": {
                        "question_text": {"type": "string"},
                        "question_type": {
                            "type": "string",
                            "enum": ["MULTIPLE_CHOICE", "FREE_RESPONSE"],
                        },
                        "choices": {"type": "array", "items": {"type": "string"}},
                    },
                    "required": ["question_text"],
                },
            },
        },
        "required": ["title", "questions"],
    },
}

Introduction: You would want to steer well away from the assistants API.

Additionally, using a function is not the best way to obtain an output from an AI like shown. It is used to invoke external functions that can provide additional information to answer a user’s question or to perform external actions.

This cookbook is developed by a third-party just to fill the vacuum of documentation about assistants.

Were you to use functions the normal way, calling an external API or performing calculation for the AI’s benefit, we can go to the API Reference to find the method prescribed for returning information:

https://platform.openai.com/docs/api-reference/runs/submitToolOutputs

The function return is plain text that is placed into the AI context. It does not need to be a specific format, but should clearly communicate the success or failure of function, error messages that let the AI see how to improve such failure in a recursive call, and in the case of success, something the AI can understand and use to answer a user.