Prompt Engineering Guide
Mastering Write SQL query
on Phi-3.5 MoE
Stop guessing. See how professional prompt engineering transforms Phi-3.5 MoE's output for specific technical tasks.
The "Vibe" Prompt
"Write a SQL query that retrieves all customers who have placed an order in the last 30 days."
Low specificity, inconsistent output
Optimized Version
SQL Query Generation Task:
**Schema Description:**
- `Customers` table: `customer_id` (PK, INT), `name` (VARCHAR), `email` (VARCHAR)
- `Orders` table: `order_id` (PK, INT), `customer_id` (FK to Customers), `order_date` (DATETIME), `amount` (DECIMAL)
**Goal:** Retrieve the `customer_id`, `name`, and `email` of all customers who have placed an order within the last 30 days.
**Constraint:** Use standard SQL.
**Thought Process:**
1. I need to select customer information: `customer_id`, `name`, `email` from the `Customers` table.
2. I need to filter customers based on their orders. This requires joining `Customers` and `Orders` tables on `customer_id`.
3. The filtering condition is `order_date` within the last 30 days. SQL's `DATE_SUB` or `INTERVAL` function can be used for this.
4. To avoid duplicate customers if they have multiple orders in the last 30 days, I should use `DISTINCT` on `customer_id`.
**SQL Query:**
Structured, task-focused, reduced hallucinations
Engineering Rationale
The optimized prompt provides a clear schema definition, explicitly states the goal, and outlines a chain-of-thought process. This structured approach helps the model understand the exact requirements, the available data, and the logical steps to construct the query. The 'Thought Process' guides the model, making it less likely to make errors related to common SQL patterns like JOINs, DISTINCT, and date filtering. It simulates a human's problem-solving approach, which is particularly effective for models sensitive to reasoning paths.
0%
Token Efficiency Gain
The generated SQL query from 'optimized_prompt' must correctly join the Customers and Orders tables.
The generated SQL query from 'optimized_prompt' must correctly filter orders within the last 30 days.
The generated SQL query from 'optimized_prompt' must select the specified customer columns and use DISTINCT where appropriate.
Ready to stop burning tokens?
Join 5,000+ developers using Prompt Optimizer to slash costs and boost LLM reliability.
Optimize My Prompts