#Structured output and Assistant API

1 messages · Page 1 of 1 (latest)

vivid flare
#

We want asssitant api to generate structured output for interacting with a tool. We want however the values that are inferred against the structure to be validated against a list of possible values as the value iffered may be a field name but not entered in same was that is referred to in database and so we need fully qualified name

trim notchBOT
#

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

#

The Assistant API from OpenAI can indeed generate structured output for interacting with a tool. This is typically done by having the assistant output a JSON that can be parsed. This JSON can contain the instructions for the tool, and the expected response format.

However, the validation of the values inferred against a list of possible values is not something that is directly handled by the Assistant API. This would typically be a part of your application logic, where you would validate the output of the assistant against your list of possible values.

For example, if the assistant is generating SQL queries, you would need to validate the field names and table names against your database schema. This is not something that the assistant can do on its own, as it does not have knowledge of your specific database schema.

In terms of structured output, the assistant can generate JSON responses. For example, in a forum post discussing a way to end the assistant loop with a function call, the original poster describes a workflow where the assistant generates a JSON with tool input, which is then passed into a function to create output. This output is then passed back into the assistant. The assistant can then decide to create a final flat text output based on these steps, or it can output another JSON that can be parsed.

Here is the described workflow:

  1. Input user message
  2. Assistant notices it needs tool → creates json with tool input
  3. Pass assistant’s tool input into function → create output
  4. Pass function output back into assistant
  5. If further steps required → repeat steps 2 - 4
  6. Assistant decides it is done → creates flat text output based on steps 1-5
#

The assistant can also generate structured output in the form of files. For files that are created by AI, they will have a purpose: assistants_output that can be a criteria when you list files. You can receive the created file in the tool attachment type of response or as an annotation, and then can download from storage, offer a download link, replace the source text in AI responses, etc.

For more information, you can refer to the following sources:


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