A Deterministic SQL Evaluator for NL2SQL Agents: Handling Aliases, Permutations and Superset Columns in ADK
Google Cloud AI engineer Rupjit Chakraborty identifies five scenarios where exact string match and naive table diff produce false negatives on semantically correct NL2SQL queries, then walks through a six-step Python normalization pipeline—value casting, column alignment by frequency counters, superset filtering, one-to-one mapping, order-invariant row hashing and equality verdict—that resolves all five at zero LLM token cost, paired with built-in trajectory scoring and a rubric-based judge for a three-layer evaluation.
The evaluator's dilemma in NL2SQL is concrete: an agent writes a query that returns the exact business answer a user needs, yet fails every standard check because it aliased a column, reordered the SELECT clause, returned rows in a different sequence, cast a price to a different precision, or included a helpful context column the gold standard omitted.
Rupjit Chakraborty, an AI engineer at Google Cloud, documents this mismatch in a December 2026 post on designing custom evaluation metrics in the Agent Development Kit. The built-in criteria—tool_trajectory_avg_score, which checks for exact match on tool arguments including the raw SQL string, and response_match_score, which measures word overlap via ROUGE-1—penalize valid variations rather than catching genuine errors.
The five failure modes are well-illustrated. First, the alias problem: a gold query returns a column named prod_sale_rev_fy25 while the agent presents it as "Revenue FY2025"—same data, different header, exact match fails. Second, the permutation problem: the agent selects email, last_login, user_id instead of user_id, email, last_login—same records, different column order, naive table diff fails. Third, the sorting problem: distributed warehouses like BigQuery do not guarantee row order without an explicit ORDER BY, so two identical queries can return rows in different sequences. Fourth, the data-type problem: a gold query casts price to DECIMAL(10,2) yielding 99.50 while the agent returns the raw numeric 99.5—mathematically equal, string-unequal. Fifth, the superset problem: a user asks for active project names, the agent also returns project_lead and due_date as helpful context, and the evaluator rejects the result for having three columns instead of one.