Skip to main content

Validated Queries

Validated queries teach Qluent how to write queries for your data. While instructions give background context and metrics define specific calculations, validated queries show Qluent the patterns—how to join tables, filter data, and structure queries.

Each example pairs a natural language question with its correct SQL. When Qluent generates a new query, it looks at similar examples and follows the same patterns.

Use case

Use validated queries when Qluent struggles with:

  • Complex joins between tables
  • Time-based filtering ("last month", "year over year")
  • Ranking and limiting results
  • Business-specific query patterns

Example

Question: What were our top 10 products by sales last month?
SELECT
p.product_name,
COUNT(*) as total_sales
FROM orders o
JOIN products p ON o.product_id = p.id
WHERE o.order_date >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1 month')
AND o.order_date < DATE_TRUNC('month', CURRENT_DATE)
GROUP BY p.product_name
ORDER BY total_sales DESC
LIMIT 10

This example teaches Qluent:

  • How to join orders and products
  • How to filter for "last month"
  • How to rank and limit results

Creating examples

Add a question users might ask and the SQL that answers it.

Tips

  • Use realistic questions - Write questions as users actually ask them
  • Focus on patterns - Joins, filtering, ranking—not specific calculations (use metrics for those)
  • Keep SQL clean - Well-formatted and commented for complex parts
  • Quality over quantity - 20 good examples beat 100 mediocre ones

What to cover

Aim for examples that show different patterns:

  • Joins: How tables connect in your data
  • Time filtering: "last week", "this quarter", "year over year"
  • Rankings: "top 10", "bottom 5"
  • Aggregations: Counting, summing, averaging

And key table combinations for your business:

  • Orders + Customers
  • Orders + Products
  • Any multi-table joins specific to your data

Validation

Qluent validates examples against your data model:

  • All referenced tables must exist and be enabled
  • All referenced columns must exist and be enabled
  • SQL must be valid

Invalid examples aren't used. Check failed queries to find questions that need examples.

When to use what

NeedUse
Background context about the businessInstructions
A calculation that must be exactMetrics
A query pattern Qluent should learnValidated queries