Enterprise Natural Language to SQL (NL2SQL) systems have evolved from single-shot query translators into autonomous data agents. Built with frameworks like Google’s Agent Development Kit (ADK) and connected to cloud data warehouses like BigQuery, these agents inspect schemas, validate queries, and synthesize answers from live data.
While ADK makes it straightforward to build an NL2SQL data agent, you need metrics that are tailored to SQL semantics to prove that the agent is accurate, reliable, and ready for production. Built-in ADK criteria, such as the tool_trajectory_avg_score (which checks for an exact match on tool arguments, including the raw SQL string) and the response_match_score (which measures word overlap by using ROUGE-1) often fall short because they penalize valid, helpful variations in LLM-generated SQL queries. When you design a custom evaluation metric in ADK, you can replace brittle string or table checks with deterministic, domain-aware evaluation. In this post, we’ll walk through the five SQL evaluation traps that break standard benchmarks and show you how to build and run a custom semantic SQL evaluator in ADK.
The evaluator’s dilemma
The evaluator’s dilemma stems from a fundamental mismatch between rigid test assertions and flexible SQL semantics. A generated query can return the exact business answer that a user needs while still failing Exact String Match, comparing raw SQL text, or Naive Table Diff,comparing result tables cell-by-cell by column header and row position.
Standard evaluation tools assume that there’s only one valid way to write a SQL query or structure a result set. This rigidity penalizes capable agents for cosmetic or user-friendly improvements, such as aliasing cryptic column headers or returning helpful context columns.
To accurately evaluate modern data agents, you can combine built-in and custom metrics in ADK across three layers:
-
Trajectory evaluation (built-in ADK metric): Verify that the agent calls the right database tools in sequence by using the
tool_trajectory_avg_scorecriterion that’s configured with thematch_typefield set toIN_ORDERand theignore_argsfield set totrue, so the criterion doesn’t flag valid SQL syntax variations as tool-argument failures. -
Deterministic semantic equivalence (custom ADK metric): Normalize both the gold-standard result set and the agent’s predicted result set into a standard form to verify data equivalence at zero LLM token cost.
-
Rubric-Based evaluation (LLM-as-a-Judge metric): Use the
rubric_based_final_response_quality_v1criterion to confirm that any extra context columns are genuinely helpful and that the agent’s natural-language summary matches the returned data.
Source Credit: https://cloud.google.com/blog/topics/developers-practitioners/designing-custom-evaluation-metrics-in-adk-for-nl2sql-data-agents/
