No matter that I try it puts in some random text at the beginning either explaining the response or just saying here is some SQL.
Just give me the SQL!!
Any ideas? I’m using the API with gpt-4 btw.
No matter that I try it puts in some random text at the beginning either explaining the response or just saying here is some SQL.
Just give me the SQL!!
Any ideas? I’m using the API with gpt-4 btw.
Prompt: I have a table called Users, and I want to get all the IDs, sorted in descending order
Answer: SELECT ID FROM Users ORDER BY ID DESC;
Strangely, I've found "Only respond with code, no extra words or explanation needed" to work really well with what you're looking for.
‘’’sql
And if that fails, since you’re using the API give it clear instructions in the system prompt and then provide a few prompt-response examples showing how you’d like it to respond
-----
You are a bla bla bla outputs SQL in a JSON object like this:
{"sql": "select * from foo"}
-----
In general, showing an example of correct output (one shot prompting) can greatly improve output format consistency. The new json output api adds more reliability.
/```sql\n(.\*)\n```/m