Skip to main content
Back to Library
Prompt Engineering Guide

Mastering Write SQL query
on Qwen 2.5 72B

Stop guessing. See how professional prompt engineering transforms Qwen 2.5 72B's output for specific technical tasks.

The "Vibe" Prompt

"Write a SQL query to get the top 5 customers by total order amount from the 'orders' table and the 'customers' table. Join them on 'customer_id'."
Low specificity, inconsistent output

Optimized Version

STABLE
You are an expert SQL query writer. Your task is to generate a SQL query based on the provided database schema and user request. <SCHEMA> Table: customers - customer_id (PK) - customer_name Table: orders - order_id (PK) - customer_id (FK to customers) - order_amount - order_date </SCHEMA> <USER_REQUEST> Show the top 5 customers by their total order amount. Include their name and the total amount. </USER_REQUEST> <PLAN> 1. Identify the tables needed: 'orders' for `order_amount` and 'customers' for `customer_name`. 2. Determine the join condition: 'customer_id' in both tables. 3. Aggregate `order_amount` by `customer_id` and `customer_name`. 4. Order the results in descending order of total amount. 5. Limit the results to 5. </PLAN> <SQL> SELECT c.customer_name, SUM(o.order_amount) AS total_order_amount FROM customers AS c JOIN orders AS o ON c.customer_id = o.customer_id GROUP BY c.customer_id, c.customer_name ORDER BY total_order_amount DESC LIMIT 5; </SQL>
Structured, task-focused, reduced hallucinations

Engineering Rationale

The 'optimized_prompt' leverages several techniques for Qwen 2.5 72B. Primarily, it establishes the model's persona as an 'expert SQL query writer', which primes it for high-quality output. It provides a highly structured input format with explicit sections for SCHEMA, USER_REQUEST, PLAN, and the expected SQL output. The inclusion of a detailed 'PLAN' guides the model through the logical steps required to construct the query, significantly reducing the chances of errors or omissions. This Chain-of-Thought (CoT) approach breaks down the complex task into smaller, manageable steps, allowing the model to 'reason' through the problem before generating the final SQL. The explicit SCHEMA prevents hallucination of table or column names. The final SQL example serves as a few-shot example, demonstrating the expected output format.

0%
Token Efficiency Gain
The optimized prompt explicitly defines the table schema.
The optimized prompt includes a detailed plan for query construction.
The optimized prompt uses a 'SQL' tag to indicate the expected query output format.

Ready to stop burning tokens?

Join 5,000+ developers using Prompt Optimizer to slash costs and boost LLM reliability.

Optimize My Prompts