Answers from the documentation; checking which model is on duty
Hi - I answer from the OpenSmartRoute documentation: routing, the API, plans and quotas, self-hosting. Ask away, or open a support ticket if you need a person.
Grounded in the docs - follow a source before acting on it.
Custom Evaluation Metrics in ADK for NL2SQL Data Agents Improve SQL Se - OpenSmartRoute
Custom Evaluation Metrics in ADK for NL2SQL Data Agents Improve SQL Semantics Testing
Google Cloud's ADK now supports custom evaluation metrics for NL2SQL agents. These metrics better handle SQL variations and improve accuracy in production.
Key points
Built-in ADK metrics often penalize valid SQL variations.
Five common SQL evaluation traps cause standard benchmarks to fail.
Custom semantic metrics normalize result sets for accurate comparison.
Evaluation pipeline includes normalization, column alignment, and row hashing.
Why it matters: Custom metrics improve evaluation accuracy, reducing false negatives and enabling more reliable, domain-aware testing of NL2SQL agents.
By OpenSmartRoute editorial · written through the router by llm-onprem
From Google Cloud AI blog - “Designing Custom Evaluation Metrics in ADK for NL2SQL Data Agents”
Introduction - Overview of NL2SQL systems and evaluation challenges
Natural Language to SQL (NL2SQL) systems convert plain language questions into database queries. These systems help users access data without knowing SQL syntax. Over time, NL2SQL has shifted from simple query translators to autonomous data agents. These agents can inspect schemas, validate queries, and generate answers from live data sources. They are often built using frameworks like Google's Agent Development Kit (ADK). These tools connect to cloud data warehouses such as BigQuery.
Evaluating the accuracy of NL2SQL agents is challenging. Standard tools often rely on exact string matches or simple table comparisons. These methods can penalize valid variations in SQL queries or results. For example, different ways of writing the same query might be marked wrong. This makes it hard to trust the evaluation results. Improving how we measure SQL correctness is essential for deploying reliable data agents.
Limitations of built-in ADK metrics - Why standard tools fall short
ADK provides built-in metrics to evaluate NL2SQL agents. One common metric is the tool_trajectory_avg_score. It checks if the agent calls the correct database tools in sequence. This metric ignores minor syntax differences by setting ignore_args to true. Another metric, response_match_score, uses word overlap measures like ROUGE-1. It compares the natural language responses generated by the agent.
However, these built-in metrics have limitations. They often rely on exact string matching or simple overlap scores. This approach can penalize valid SQL variations that are more readable or user-friendly. For instance, aliasing columns with the AS keyword changes the string but not the meaning. Similarly, different column orders or extra helpful columns can cause false negatives. These shortcomings highlight the need for custom evaluation metrics that understand SQL semantics better.
The five SQL evaluation traps - Common pitfalls in SQL result comparison
Standard evaluation methods often fail in five common scenarios. These are known as evaluation traps. Recognizing these helps improve the accuracy of NL2SQL testing.
Elastic emphasizes data retrieval over model improvements, integrating search technology into AI agent workflows to improve data access and security.
The first trap is the alias problem. Agents often alias columns to make output more understandable. For example, changing a column name from a cryptic ID to a descriptive label. String-based checks see these as different queries, even though they mean the same. The second trap is the permutation problem. The order of columns in a SELECT statement does not affect the data's meaning. Different column orders should be considered equivalent.
The third trap involves row order. When a query does not specify an ORDER BY clause, the database can return rows in any order. Comparing row sequences directly can lead to false negatives. The fourth trap is data type normalization. Numeric values might be returned with different precisions or castings, but still represent the same data. Comparing raw strings or types can cause errors.
The fifth trap concerns extra columns. Capable agents often include additional context columns to answer follow-up questions. While these columns are helpful, naive comparison methods may reject the result for having more columns than expected. Recognizing these traps is crucial for building better evaluation tools.
Designing custom semantic metrics - Approach and normalization steps
To address these evaluation challenges, custom semantic metrics are necessary. These metrics compare the actual data content rather than raw SQL strings or exact tables. The goal is to normalize both the gold standard and predicted results into a standard form.
The process begins with standard value normalization. This step converts numbers, dates, and text into comparable formats. Numbers are rounded to a fixed precision, dates are formatted as ISO-8601 strings, and whitespace is stripped from text. Next, columns are aligned by value counts. Each column is represented as an unordered frequency counter. This neutralizes aliasing and column order differences.
The third step filters out extra columns if allowed. It ensures that the predicted result contains at least the required columns. Then, a one-to-one column mapping is established. Each gold column is matched to a predicted column with identical value distributions. This step handles permutations and aliasing simultaneously. Finally, the rows are hashed in an order-invariant way. This ensures that row order does not affect the comparison. These normalization steps create a robust basis for semantic evaluation.
Implementing the custom evaluator - Code structure and key functions
Implementing a custom evaluator involves writing a Python module that performs the normalization and comparison steps. The core class, called SemanticSQLEvaluator, evaluates the semantic equivalence between gold and predicted result sets. It uses helper functions to normalize values and compare columns.
The main evaluate method first checks if the result sets are empty or have mismatched row counts. It then normalizes both tables into 2D matrices. Each column is converted into a value count using collections.Counter. These counters help compare columns regardless of aliasing or order. The method then filters candidate columns based on value counts.
Next, it searches for a valid one-to-one column mapping. For each candidate mapping, it hashes the rows in an order-invariant way. If the predicted rows match the gold standard under any mapping, the evaluation passes. Otherwise, it fails. This approach ensures that the evaluation focuses on the actual data content, not superficial differences.
Handling aliasing and column permutations - Techniques for robust comparison
Alias handling involves comparing columns based on their value distributions rather than their names. By representing each column as a collection of normalized values, the evaluator ignores differences in column headers. This approach neutralizes aliasing issues.
Column permutations are addressed by trying all valid one-to-one mappings between gold and predicted columns. Each mapping pairs columns with identical value counts. The evaluator then compares the rows projected through these mappings. If any mapping produces matching data, the result is considered correct. This method ensures that different column orders do not penalize valid queries.
These techniques make the evaluation more tolerant of cosmetic differences. They focus on whether the data returned is semantically equivalent, regardless of how it is structured or labeled.
Row order and data type normalization - Ensuring order-invariance and consistency
Row order can vary depending on database execution plans. To prevent this from causing false negatives, the evaluator hashes rows in an order-invariant way. It projects each row through the established column mapping and counts the resulting tuples. This counting process ignores the sequence of rows, focusing only on their content.
Data type normalization ensures that numeric and date values are comparable. Numbers are rounded to a fixed precision, and dates are formatted uniformly. Text values are stripped of whitespace. This normalization prevents differences in formatting or casting from affecting the evaluation. It makes the comparison focus solely on the actual data, not its presentation.
Order-invariance and data normalization are essential for accurate semantic evaluation. They allow the system to recognize equivalent results even when minor formatting differences exist.
Integrating custom metrics into ADK - Registration and test setup
To use the custom evaluator in ADK, it must be registered as a Python metric. This involves creating a class that implements the evaluation logic and registering it in the evaluation configuration. The custom metric is then invoked during testing, alongside built-in criteria.
The registration process includes defining the custom metric class, which inherits from ADK’s EvalMetric. The class implements methods for normalization and comparison. Once defined, it is registered via the custom_metrics field in the evaluation setup. This allows ADK to call the custom evaluator during test runs.
Testing the custom metric requires realistic, multi-row fixtures. These fixtures help ensure that the evaluator correctly handles various SQL variations. Pairing the custom metric with existing criteria provides a comprehensive evaluation framework. This setup improves the reliability of NL2SQL system testing.
Why it matters - Benefits of domain-aware evaluation for data agents
Using domain-aware, custom evaluation metrics improves the accuracy of NL2SQL agents. It reduces false negatives caused by superficial differences. This leads to more reliable assessments of agent performance. Better evaluation results enable developers to refine their models more effectively.
Domain-aware metrics also support more natural interactions. Agents can alias columns or include helpful context without being penalized. This encourages more user-friendly query generation. Overall, custom semantic evaluation makes data agents more trustworthy and useful in real-world scenarios.
It also helps teams deploy agents in production with confidence. They can verify that the agent truly understands the data and produces correct results. This reduces errors and improves user satisfaction. Custom metrics are a key step toward more robust, flexible NL2SQL systems.
How OpenSmartRoute helps - what a team routing through OpenSmartRoute does with Custom Evaluation Metrics in ADK for NL2SQL Data Agents Improve SQL Semantics
OpenSmartRoute is an open-source router for AI requests. It manages how requests are sent to models, agents, and tools. Teams using OpenSmartRoute can set rules to pin requests to specific models or regions. They can also score each candidate based on quality, cost, speed, and safety. This helps optimize request routing for different needs.
Routing requests through OpenSmartRoute allows teams to incorporate custom evaluation metrics into their workflows. They can measure how well their NL2SQL agents perform using these domain-aware metrics. The platform records the accuracy and cost of each request, helping teams identify the best models and configurations. They can also learn from outcomes by adjusting weights and rules.
With OpenSmartRoute, teams can deploy their improved NL2SQL agents confidently. They can track performance over time and ensure that the agents meet their standards. The platform’s flexibility supports integrating custom evaluation metrics, making it easier to develop reliable, production-ready data agents. It also provides visibility into request costs and model rankings, helping optimize overall system efficiency.