Fine-tuning GPT-4o-mini for SQL generation - results and tips
Sarah ChenMar 22, 2026
I fine-tuned GPT-4o-mini to generate SQL queries for our specific database schema and the results are impressive. Sharing my approach.
Dataset
Results
So the fine-tuned mini model outperforms the base GPT-4o at a fraction of the cost!
Key tips
1. Include the schema in every training example's system prompt 2. Add error correction examples (wrong SQL -> correct SQL) 3. Use 2 epochs max — overfitting happens fast 4. Include diverse question phrasings for the same query6.1k views33 replies88 likes
2 Replies
This is likely related to your network layer, not the API itself. Make sure you're properly handling the SSE stream. Some common causes:
1. Proxy or load balancer buffering chunks
2. Missing Connection: keep-alive header
3. Client-side buffer overflow
Try using the SDK's built-in streaming which handles these edge cases:
with client.chat.completions.create(
model="gpt-4o",
messages=[...],
stream=True
) as stream:
for text in stream:
# This handles all edge cases
pass
It was our nginx proxy buffering! Added proxy_buffering off; and the issue disappeared. Thanks!
Log in to reply to this topic.