Prompt Engineering Guide
Mastering Write SQL query
on Mistral Large 2
Stop guessing. See how professional prompt engineering transforms Mistral Large 2's output for specific technical tasks.
The "Vibe" Prompt
"Write a SQL query to get the top 10 customers by total order amount this year."
Low specificity, inconsistent output
Optimized Version
You are a highly skilled SQL query generator for a PostgreSQL database.
**Instructions:**
1. Generate a SQL query to retrieve the top 10 customer IDs and their total order amounts.
2. Consider only orders placed in the current calendar year (2023).
3. Assume tables `customers` (columns: `customer_id`, `customer_name`) and `orders` (columns: `order_id`, `customer_id`, `order_date`, `total_amount`).
4. The output should be a single, executable SQL query.
5. Order the results in descending order of total amount.
**Thought Process:**
* I need to join `customers` and `orders` tables.
* I need to filter orders by `order_date` for the current year.
* I need to group by `customer_id` and sum `total_amount`.
* I need to order by the summed amount descending.
* Finally, I need to limit the results to 10.
**SQL Query:**
Structured, task-focused, reduced hallucinations
Engineering Rationale
The optimized prompt provides a clear persona, detailed instructions, explicit table and column names, and a chain-of-thought breakdown. This specificity reduces ambiguity, guides the model through the logical steps, and helps it generate a more accurate and robust SQL query. The 'Thought Process' section acts as a strong few-shot example or a clear internal monologue for the model, improving output quality without necessarily increasing prompt length significantly for complex queries.
0%
Token Efficiency Gain
The generated SQL uses `JOIN` correctly.
The generated SQL filters by `EXTRACT(YEAR FROM order_date) = 2023` (or equivalent).
The generated SQL uses `GROUP BY customer_id`.
Ready to stop burning tokens?
Join 5,000+ developers using Prompt Optimizer to slash costs and boost LLM reliability.
Optimize My Prompts