4 ms·
How do I make it return ONLY sql? No matter that I try it puts in some random text at the beginning either explaining the response or just saying here is some
by lgkk 3y ago
How do I make it return ONLY sql?
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.
- Oras 3y agoAt the end add: Just return the SQL query, do not explain the results.
- throwuwu 3y agoWeird that 4 wouldn’t understand a clear directive to only output code but you can use the old trick of ending your message with three backticks and the language name: ‘’’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
- Wingy 3y agoIf you're using the API, maybe use a regex? /```sql\n(.\*)\n```/m
- fzzzy 3y agoTry the new json format output. You have to turn it on in the api call, then use a prompt like this: ----- 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.
- capableweb 3y agoSystem: You are a SQL query assistant. You should only respond with valid SQL queries. Only respond with code, no extra words or explanation needed. 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.
- adeelk93 3y agoUse the function calling API - works really well for getting structured responses