How to get a raw list as assistant's output?

Hi, is there any way to configure the assistant to provide outputs as a raw list without any additional text? This is what the instructions for my assistant currently look like:

assistant = client.beta.assistants.create(
    name="Books Adviser",
    instructions='You are an expert on books. Your role is to recommend some books based on the data provided by a user. The output should be a Python list of dictionaries with keys ["Title"], ["Author"], and ["Topic"]. The list should be named "books". Do not write anything else; provide just a list.',
    tools=[{"type": "retrieval"}],

Everything worked fine until I enabled ‘Knowledge Retrieval’ and uploaded a file. However, now it is quite common to see outputs such as “Based on your data, here are some books you may enjoy” or “Enjoy reading!”. How can I configure the assistant to output only the raw list as specified in the instructions?

I guess it can be done with fine-tuning or function calling, but I’ve not used any of these before. If it is possible, what solution will be more effiecent (cost, speed)? Or maybe there is a better option?

Welcome to the community!

Have you considered forcing its response as a json format?

My thinking here is that you might be able to force it into providing a text list represented as a JSON file, and then use that format to programmatically turn it into the kind of data structure you need. This is the quickest and easiest solution that comes off the top of my head.

It’s not able to directly output raw data structures from a prompt directly. If it does, said data structure would be coming from its code interpreter/advanced data analysis capabilities. What it would do would be to write the script and execute the script to create some kind of data structure like that, but again, that still requires more leg work on the programming end than direct prompt → data structure. Hence why I think working with the json format would be the best solution here.

Let me know if you need more help or if that doesn’t work for you.


If you do get the dict with the list consistently then consider to simply remove all extra, unnecessary content before and after the list.
This should be a simple and robust solution but I admit that making sure you really get only what you want is more cost effective.

1 Like

Quick question, why not JSON? Can you please test this and see if it works for you?
Please answer with a JSON response in the following format. No salutes, no explanations, no thank you, nothing other than the specified JSON.
“Title”: “Placeholder Title 1”,
“Author”: “Placeholder Author 1”,
“Topic”: “Placeholder Topic 1”
“Title”: “Placeholder Title 2”,
“Author”: “Placeholder Author 2”,
“Topic”: “Placeholder Topic 2”
Make sure the JSON is valid!

edit: Just saw Macha’s reply. +1 there. :yum: