Skip to main content
Back to Library
Prompt Engineering Guide

Mastering Write SQL query
on Groq Llama 3.1 70B

Stop guessing. See how professional prompt engineering transforms Groq Llama 3.1 70B's output for specific technical tasks.

The "Vibe" Prompt

"Hey Groq Llama 3.1 70B, write me an SQL query to retrieve all orders placed in the last 30 days that have a total amount greater than 1000. I need the order ID, customer ID, order date, and total amount. Also, join it with the customers table to get the customer's name. The tables are 'orders' with columns 'order_id', 'customer_id', 'order_date', 'total_amount' and 'customers' with columns 'customer_id', 'customer_name'."
Low specificity, inconsistent output

Optimized Version

STABLE
SQL Query Generation Task: **Goal:** Retrieve specific order details for recent, high-value orders, including customer names. **Database Schema:** * **Table:** `orders` * `order_id` (INT, PRIMARY KEY) * `customer_id` (INT, FOREIGN KEY to `customers`) * `order_date` (DATE) * `total_amount` (DECIMAL(10, 2)) * **Table:** `customers` * `customer_id` (INT, PRIMARY KEY) * `customer_name` (VARCHAR(255)) **Requirements:** 1. Select `orders.order_id`, `orders.customer_id`, `orders.order_date`, `orders.total_amount`, and `customers.customer_name`. 2. Filter orders placed within the last 30 days from the current date. 3. Filter orders where `total_amount` is greater than 1000. 4. Join `orders` and `customers` tables on `customer_id`. **Step-by-step thought process for query construction:** 1. **Identify necessary columns:** `order_id`, `customer_id`, `order_date`, `total_amount` from `orders` and `customer_name` from `customers`. 2. **Determine tables involved:** `orders` and `customers`. 3. **Specify join condition:** `orders.customer_id = customers.customer_id`. 4. **Apply date filter:** `order_date >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)` (assuming MySQL-like syntax for `CURDATE()` and `DATE_SUB`). 5. **Apply amount filter:** `total_amount > 1000`. 6. **Combine all parts into a `SELECT`, `FROM`, `JOIN`, and `WHERE` clause.** **Generated SQL Query:**
Structured, task-focused, reduced hallucinations

Engineering Rationale

The optimized prompt works better because it provides a clear, structured breakdown of the request. It explicitly defines the database schema, lists requirements numerically, and most importantly, includes a 'step-by-step thought process'. This chain-of-thought guides the model through the logical construction of the SQL query, reducing ambiguity and increasing the likelihood of generating a correct and efficient query. By outlining each logical step, the model can 'reason' through the problem more effectively, mimicking human problem-solving. This structure also ensures all critical details are presented upfront in an organized manner.

0%
Token Efficiency Gain
The 'vibe_prompt' is casual and relies heavily on implicit understanding.
The 'optimized_prompt' clearly enumerates schema details, requirements, and a CoT process.
Both prompts target the same SQL query generation task.

Ready to stop burning tokens?

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

Optimize My Prompts