Skip to main content
Back to Library
Prompt Engineering Guide

Mastering Write SQL query
on Cerebras Llama 3.1 70B

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

The "Vibe" Prompt

"Write a SQL query that retrieves customer names who placed orders in the last 30 days."
Low specificity, inconsistent output

Optimized Version

STABLE
You are a highly-skilled SQL query generator. Your task is to produce a correct and efficient SQL query based on the user's request. **Schema Context:** We have two tables: - `customers`: `customer_id` (PK, INT), `customer_name` (VARCHAR) - `orders`: `order_id` (PK, INT), `customer_id` (FK, INT), `order_date` (DATE) **User Request:** Retrieve the names of customers who have placed an order within the last 30 days. **Constraint:** - Provide only the SQL query, no additional text or explanations. **Thought Process (Chain of Thought):** 1. **Identify Tables:** The request involves 'customer names' and 'orders', so `customers` and `orders` tables are needed. 2. **Identify Join Condition:** To link customers to their orders, we need to join `customers` and `orders` on `customer_id`. 3. **Identify Filtering Condition:** The condition is 'orders in the last 30 days'. This translates to `order_date >= DATE('now', '-30 days')` (for SQLite-like syntax) or `order_date >= CURRENT_DATE - INTERVAL '30 days'` (for PostgreSQL/MySQL-like syntax). Given no specific database, I'll use a widely compatible approach or assume a common SQL dialect if not specified. 4. **Identify Desired Output:** The request asks for 'customer names', so `customers.customer_name` should be selected. 5. **Handle Duplicates:** A customer might have placed multiple orders within the last 30 days. To get unique customer names, `DISTINCT` is necessary. **SQL Query:**
Structured, task-focused, reduced hallucinations

Engineering Rationale

The optimized prompt works by providing extensive context, a clear role for the LLM, and a detailed chain-of-thought. The schema definition eliminates ambiguity about table and column names and types. The 'Thought Process' guides the model through the logical steps required to construct the query, preventing common errors such as missing joins, incorrect date filtering, or duplicate results. The explicit constraint to 'Provide only the SQL query' ensures a clean output. This structured approach mimics an expert's problem-solving method, leading to more accurate and reliable SQL generation.

0%
Token Efficiency Gain
The generated SQL query correctly identifies customers with recent orders.
The generated SQL query handles potential duplicate customer names.
The generated SQL query uses appropriate date filtering for 'last 30 days'.

Ready to stop burning tokens?

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

Optimize My Prompts