The assistants API can only return a function-call for such an application. You would need to handle the AI’s output of a function it wrote, supplying all the code, processing, database access and query, and returning the response back to the AI. While ensuring the user didn’t decide to ask about mister drop table.
I’ve done something very similar to this! I have a postgreSQL database I wanted to get data from using my agent, so I used an ORM (in my case SQLAlchemy) to connect to it in Python. I created a role in my database that only gave me read access so I wouldn’t mess anything up, and then made a function that takes in a plain text SQL query, executes it, and returns a string with the outputted values. Then all that was left was adding the function to my agent’s toolbelt.