Prompt Engineering Guide
Mastering Write SQL query
on Claude 3.5 Sonnet
Stop guessing. See how professional prompt engineering transforms Claude 3.5 Sonnet's output for specific technical tasks.
The "Vibe" Prompt
"Write a SQL query to get all orders for customer ID 123."
Low specificity, inconsistent output
Optimized Version
You are an expert SQL query generator. Your task is to write a SQL query to retrieve all orders for a specific customer.
<thought>
1. Identify the core request: retrieve orders for a customer.
2. Determine the necessary tables: 'orders' table (assuming it contains customer references).
3. Determine the filtering condition: 'customer_id' = 123.
4. Determine the columns to select: all columns from the 'orders' table (SELECT *).
5. Construct the SQL query using SELECT, FROM, and WHERE clauses.
</thought>
Write a SQL query to get all columns from the 'orders' table where the 'customer_id' is 123. Ensure the query is valid for a standard SQL database (e.g., PostgreSQL, MySQL).
Structured, task-focused, reduced hallucinations
Engineering Rationale
The optimized prompt provides clear instructions, defines the persona (expert SQL query generator), and includes a chain-of-thought section. This C-o-T breaks down the problem into logical steps, helping the model understand the exact requirements and thought process, leading to a more accurate and robust SQL query. It guides the model through table identification, filtering, and column selection, reducing ambiguity.
0%
Token Efficiency Gain
The 'optimized_prompt' clearly states the goal of generating an SQL query.
The 'optimized_prompt' uses a chain-of-thought to guide the model's reasoning.
The 'optimized_prompt' specifies the target customer ID (123) and table ('orders').
Ready to stop burning tokens?
Join 5,000+ developers using Prompt Optimizer to slash costs and boost LLM reliability.
Optimize My Prompts