Skip to main content
Back to Library
Prompt Engineering Guide

Mastering Write SQL query
on Mixtral 8x22B

Stop guessing. See how professional prompt engineering transforms Mixtral 8x22B's output for specific technical tasks.

The "Vibe" Prompt

"SQL query to get all orders for customer 'John Doe'. The customer ID is 123. The orders table has columns: order_id, customer_id, order_date, total_amount. The customers table has columns: customer_id, first_name, last_name."
Low specificity, inconsistent output

Optimized Version

STABLE
You are an expert SQL query generator. Your task is to write a SQL query. Think step by step. ### Database Schema: ```sql CREATE TABLE Customers ( customer_id INT PRIMARY KEY, first_name VARCHAR(50), last_name VARCHAR(50) ); CREATE TABLE Orders ( order_id INT PRIMARY KEY, customer_id INT, order_date DATE, total_amount DECIMAL(10, 2), FOREIGN KEY (customer_id) REFERENCES Customers(customer_id) ); ``` ### Task: Retrieve all orders for the customer named 'John Doe'. ### Constraints: - Use the provided schema. - The customer's `customer_id` is 123. ### Thought Process: 1. Identify the target table: We need order details, so `Orders` is the primary table. 2. How to link customer name to orders? We need to join `Orders` with `Customers` on `customer_id`. 3. Filter for the specific customer: Filter `Customers.first_name` and `Customers.last_name` (or `Customers.customer_id`). The prompt explicitly provides `customer_id` 123, which is more direct. 4. Select all columns from `Orders`. ### SQL Query:
Structured, task-focused, reduced hallucinations

Engineering Rationale

The optimized prompt works by providing a highly structured and detailed request. It explicitly defines the role ('expert SQL query generator'), clearly separates the schema from the task, and includes explicit constraints. The most significant improvement is the 'Thought Process' section, which guides the model through the logical steps required to construct the query. This chain-of-thought prompting reduces ambiguity, helps the model understand the exact requirements, and minimizes errors by breaking down the complex task into smaller, manageable steps. By providing the `customer_id` directly in constraints, it guides the model to use the most efficient filtering method rather than joining on names first.

0%
Token Efficiency Gain
The generated query correctly joins `Orders` and `Customers` tables.
The generated query filters by `customer_id = 123`.
The generated query selects all relevant columns for orders.

Ready to stop burning tokens?

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

Optimize My Prompts