SQL Query Generation from Ambiguous Natural Language
30 Production Challenge Scenarios • Real-Time Automated Quality Scoring
Interactive Prompt Engineering Lab
Test and score your prompts against real-world enterprise scenarios. Get immediate 4-axis quality telemetry, negative guardrail verification, and golden reference prompts.
1. Authoritative Persona
Expert role + zero fluff
2. Deterministic Schema
XML tags + JSON / keys
3. Negative Guardrails
NEVER / fallback rules
4. Token Efficiency
150–1,800 chars concise
Data Engineering & RAGIntermediate
SQL Query Generation from Ambiguous Natural Language
Convert an ambiguous business question ("Who are our top customers this quarter?") into a safe, deterministic PostgreSQL query with explicit date filters, aggregations, and limit clauses.
Target Input Context / Untrusted Data:
Database Schema: - customers (id, name, created_at, plan_tier) - orders (id, customer_id, total_amount_cents, status, created_at) Ambiguous Prompt: "Who are our top customers this quarter?"
Quality Requirements & Guardrails:
Define a Lead Analytics Engineer persona.
Resolve "top" unambiguously as total completed order spend in cents.
Resolve "this quarter" using date_trunc('quarter', CURRENT_DATE).
Filter out cancelled, refunded, or failed order statuses.
Include a LIMIT 10 clause and performance index comment.
Your System Prompt Draft
49 chars~12 tokens
Golden Reference Architecture (100% Quality Benchmark)
<system_instructions>
You are a Principal Analytics & SQL Engineer.
Translate the business request "Who are our top customers this quarter?" into an efficient PostgreSQL query.
AMBIGUITY RESOLUTION & SAFETY:
1. BUSINESS METRIC: Define "top" strictly as total settled revenue (`SUM(total_amount_cents) / 100.0`).
2. STATUS FILTERING: Filter strictly for completed orders (`orders.status = 'completed'`), explicitly excluding pending or refunded records.
3. TEMPORAL ANCHORING: Use dynamic PostgreSQL date functions (`orders.created_at >= date_trunc('quarter', CURRENT_DATE)`) rather than hardcoded dates.
4. PROTECTION: Enforce `LIMIT 20` to prevent unconstrained result sets.
5. Output query inside <sql_query> tags with a brief technical commentary on required indexes.
</system_instructions>