Assistants API + SQL Retrieval

You can use markdown to explain the assistant your current schema

doesnt work great on 3.5, you will have to use GPT4 or above.

Remember you will need to add some locks to prevent hacking, like searching for undesired words (DELETE, UPDATE, etc)

Also a big tip:

  • Give GPT a simplified schema, and then you can replace it after.

For example

This will be a nice self-explain schema

CONTACTS table

  • id
  • name
  • last_name
  • gender | enum(female,male)
  • phone_number

Even in your real DB, you have “cell” instead of phone_number, but it is super hard to explain to GPT that “cell” means “phone_number”

Instead you tell GPT your column is called “phone_number” and then you can replace that string with “cell”

Even a better tip (i havent test it yet), could be to ask GPT to retrieve separately the elements of the query (select columns, wheres, orders, limit, etc).

That way it will be easier to run a security check before runing the query, like no limit above 100, etc)