Lecture translation + study notes

Custom Model Evaluations for Text-to-SQL

A practical case study on selecting the best LLM for a cricket question-answering feature—using your own data, budget, and success criteria.

About this document: This is a readable English translation and study guide based on the supplied Hindi–English lecture transcript. Classroom repetition and live-demo remarks have been condensed; the method and reasoning have been retained.

English translation

1. From theory to hands-on evaluation

The course now moves from theory to practical work. Earlier sessions separated LLM evaluations into model evaluations and application evaluations. Model evaluations include public benchmarks and custom evaluations. Benchmarks identify strong candidate models in general; custom model evaluations answer the more useful question: Which model is best for my specific application?

A public coding or reasoning leaderboard may give a shortlist, but it cannot tell you which model works best with your database schema, prompts, traffic pattern, cost limit, and users. That requires a custom evaluation.

2. Case study: a cricket question-answering assistant

Imagine working for a cricket website such as ESPNcricinfo. During live matches, users ask questions such as “Who has scored the most runs against Bumrah?” or “How many wickets did Bumrah take in the previous India–Pakistan match?” Traditionally, analysts query the cricket database and send answers to the live-commentary team. At high-traffic moments this manual workflow does not scale.

The proposed feature lets a fan ask a question in plain English. An LLM receives the question plus the database schema, generates SQL, the system runs the SQL against the cricket database, and the result is shown to the user. In effect, the LLM automates the analyst’s database-query task.

3. The actual model-selection problem

The LLM is the system’s “brain,” so the team needs to select one deliberately. The lecture sets three practical requirements:

  • Budget: monthly spending must stay within the agreed limit.
  • Speed: users should not wait too long for an answer.
  • Quality: generated SQL must return the correct result for real cricket questions.

The workflow is therefore: filter candidate models by cost, check latency, then compare their task-specific accuracy on a representative evaluation set.

4. Estimating cost before testing

Cost depends on input tokens, output tokens, request volume, and each provider’s token pricing. The lecture uses a working estimate of about 400 input tokens (question, schema, instructions, and examples), 100 output tokens (the SQL query), and 5,000 queries per day. Real demand will be spiky—major matches produce far more traffic—so this should be treated as a planning estimate, not a fact.

For each candidate, calculate per-query cost, multiply by expected monthly volume, convert currency if needed, and discard models that exceed budget. This stops the team from spending evaluation time on an unaffordable model.

5. Selecting candidates from leaderboards

Text-to-SQL leaderboards can be useful, but the lecture advises caution: they may be outdated, use fine-tuned systems rather than base models, or provide unclear methodology. Because SQL generation is a programming-like task, a current coding leaderboard can be used as a rough proxy to produce a shortlist.

This is only a starting point. A coding ranking does not prove Text-to-SQL success for the cricket database. After applying cost and latency filters, the remaining candidates must be evaluated directly on the target task.

6. Building the golden evaluation dataset

Create a golden dataset from realistic user questions. For every question, a knowledgeable analyst writes the correct SQL query. The lecture uses 50 examples as a small initial evaluation set. The questions should cover the kinds of requests users will actually make: player statistics, match history, teams, tournaments, rankings, filters, aggregations, and ordering.

The golden dataset should be high quality. If the reference SQL is wrong or the questions are unrepresentative, the final score will be misleading. As the product changes, the dataset should grow with new real-world failure cases.

7. The right way to score generated SQL

Do not compare generated SQL with golden SQL character by character. Multiple SQL statements can produce the same correct result. Instead, execute both the golden SQL and the model-generated SQL against the same database and compare their result tables.

If the two result sets are equivalent, the generated SQL is correct for that evaluation item—even if the query text is different. Repeat this for every question, then calculate execution accuracy: correct result sets divided by total questions. Run the exact same process for every candidate model.

8. Result comparison and orchestration

A robust evaluator compares result tables carefully. It checks row counts, normalizes equivalent values (for example, 2 and 2.0, or harmless decimal precision differences), and handles row order. Results can be sorted before comparison when order is irrelevant. If the correct query uses an ORDER BY clause and order matters, preserve and compare the order.

The final orchestration script loads each model, sends every golden-dataset question with the schema and prompt, executes both SQL queries, calls the evaluator, and records the scores. The model with the best acceptable trade-off between execution accuracy, latency, and price is the practical choice.

Custom evaluation workflow

1

Define task

English cricket question → SQL → database result.

2

Set constraints

Budget, expected traffic, and acceptable latency.

3

Shortlist models

Use current public evidence only as a first filter.

4

Create gold data

Realistic questions paired with analyst-approved SQL.

5

Run models

Give each model the same prompt, schema, and questions.

6

Execute & compare

Compare result sets, not the text of SQL queries.

7

Choose & monitor

Select the best trade-off; add production failures back to the eval set.

Key revision notes

Benchmark ≠ custom eval

Benchmarks identify broad model capability. Custom evals tell you what works on your application.

Execution accuracy matters

For Text-to-SQL, a query is correct when it returns the right result—not when it looks identical to a reference query.

Quality is multidimensional

A model must satisfy accuracy, cost, and latency. The highest raw accuracy may not be deployable.

Golden data is a product asset

Maintain it continuously. Each important production failure is a candidate new test case.

Metrics and checks

MeasureHow to calculate / inspectWhy it matters
Execution accuracyEquivalent result sets ÷ total questionsDirectly tests whether the database answer is correct.
Monthly cost(Input tokens × input rate + output tokens × output rate) × monthly requestsEnsures the model fits the business budget.
LatencyMeasure end-to-end response time, preferably percentile values such as p95Protects live user experience during traffic spikes.
Result-set equalityRows, normalized values, and order when requiredAvoids false failures caused by different but equivalent SQL.
CoverageCheck task types represented in the golden datasetPrevents a high score from hiding unsupported user requests.

Pseudocode for the evaluator

for model in candidate_models: correct = 0 for example in golden_dataset: generated_sql = model.generate(question=example.question, schema=schema) expected = database.run(example.golden_sql) actual = database.run(generated_sql) if equivalent_result_sets(expected, actual, order_matters=example.order_matters): correct += 1 execution_accuracy[model] = correct / len(golden_dataset)

Practical conclusion

Use leaderboards to narrow the search, not to make the final decision. The final decision should be based on a repeatable custom evaluation that mirrors your users’ real questions and measures the outcomes your product actually needs.

Self-check questions

  1. Why is string matching an unreliable way to evaluate generated SQL?
  2. Which three product constraints are used to filter candidate models in this case study?
  3. What should a Text-to-SQL golden dataset contain?
  4. When should result-table order be preserved during comparison?
  5. Why should a production failure be added to the evaluation dataset?