Skip to main content
Back to Library
Prompt Engineering Guide

Mastering Write SQL query
on Claude 3.5 Haiku

Stop guessing. See how professional prompt engineering transforms Claude 3.5 Haiku's output for specific technical tasks.

The "Vibe" Prompt

"Write an SQL query to select all users named 'John Doe' from the 'users' table."
Low specificity, inconsistent output

Optimized Version

STABLE
SQL Query Generation Task: 1. User Request: Select all users named 'John Doe' from the 'users' table. 2. Database Context: Table: `users` Relevant Column: `name` (VARCHAR) 3. Task Breakdown & Thought Process (Chain of Thought): - Identify the target table: `users`. - Identify the selection criteria: users with the name 'John Doe'. - Identify the column for the criteria: `name`. - Determine the SQL clause for selection: `SELECT *` for all columns. - Determine the SQL clause for filtering: `WHERE`. - Construct the condition: `name = 'John Doe'`. - Combine clauses into a complete query. 4. Generated SQL Query: ```sql SELECT * FROM users WHERE name = 'John Doe'; ```
Structured, task-focused, reduced hallucinations

Engineering Rationale

The optimized prompt leverages chain-of-thought and a structured format to guide the model's reasoning. By explicitly breaking down the task, providing database context (even if minimal in this example), and pre-thinking the SQL construction steps, it significantly reduces ambiguity and improves the likelihood of generating the correct and efficient query. It primes the model to output the SQL directly after its reasoning, rather than generating introductory text or further dialogue.

-400%
Token Efficiency Gain
The 'vibe_prompt' is concise and direct.
The 'optimized_prompt' clearly separates instructions from output.
The 'optimized_prompt' includes a 'Database Context' section.

Ready to stop burning tokens?

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

Optimize My Prompts