Skip to content Skip to footer

How to Deploy Enterprise NL2SQL Agents With Reliable Evaluation and Lower Testing Costs

What Happened

Enterprise natural-language-to-SQL agents need evaluation that checks data correctness, not just whether generated SQL resembles a reference query. Research on Google ADK and BigQuery describes a three-layer approach: validate tool execution, compare query results deterministically, and assess the final explanation against a rubric. Exact SQL matching, ROUGE-1, and naive table comparisons can reject otherwise correct answers. [1]

The proposed custom metric compares rows returned by the latest execute_sql_query call. It normalizes values, aligns columns by value distribution, establishes a one-to-one column mapping, and compares unordered row counts. This accommodates aliases, reordered columns and rows, and some numeric formatting differences without spending LLM tokens on the result comparison itself. [1]

The broader engineering lesson aligns with Simon Willison’s discussion of coding agents: generating code does not eliminate the need to decide what to build or ensure that software is secure, performant, and useful. For data agents, that responsibility includes defining what a correct answer actually means. [2]

Why It Matters to Businesses

  • More trustworthy release decisions: Equivalent SQL queries should not fail merely because their syntax differs. Conversely, plausible prose should not compensate for incorrect data. Separate checks make those distinctions visible. [1]
  • Lower evaluation inference costs: Deterministic result comparison avoids LLM token charges for that layer. Query execution, test infrastructure, and rubric-based answer assessment still incur costs. [1]
  • Clearer failure ownership: Tool-sequencing failures, incorrect results, and misleading explanations require different fixes. A single aggregate score can conceal those differences.
  • Safer platform changes: A representative regression suite gives teams evidence when changing models, prompts, tools, or data schemas.

The architecture decision is not simply which model to deploy. It is how to establish an enforceable contract between user intent, permitted queries, returned data, and the final answer.

Kimbodo Engineering Perspective

We would treat evaluation as a production dependency, not a demonstration checklist. The three layers answer distinct questions: Did the agent use the expected tools? Did it retrieve the expected data? Did it explain that data accurately? The ADK approach provides separate metrics for each: tool_trajectory_avg_score, semantic_sql_result_match, and rubric_based_final_response_quality_v1. [1]

Comparison rules must follow business semantics. Unordered matching is appropriate for many tabular answers, but not when the user explicitly requests a ranking or sort. Leading-zero codes and large identifiers must remain strings when numeric conversion would change their meaning. Extra columns should be accepted only where the answer contract permits them. [1]

We would also avoid treating successful fixture matching as proof of SQL correctness. Different queries can return identical results on a small dataset. Realistic multi-row fixtures reduce accidental matches; additional edge cases should exercise duplicates, nulls, ties, and access boundaries. The research specifically recommends realistic multi-row fixtures to strengthen comparison. [1]

How We Would Implement It

Separate execution, evaluation, and presentation

We would expose BigQuery through a controlled query tool rather than give the agent unrestricted database access. The tool boundary would enforce identity, dataset permissions, execution limits, and structured result capture. Evaluation would inspect those captured results separately from the user-facing explanation.

Build a versioned regression suite

  • Define fixtures: Store prompts, expected tool calls, gold-standard rows, and reference answers in nl2sql.evalset.json, with metric configuration in eval_config.json. [1]
  • Specify comparison policies: Declare whether row order matters, whether additional columns are acceptable, and which fields require exact string preservation.
  • Gate releases by failure type: Run deterministic checks across the suite and apply rubric-based assessment to final answers. Review failures separately rather than relying only on a blended score.
  • Preserve reproducibility: Record model, prompt, tool, schema, fixture, and evaluator versions alongside test results.

Use managed infrastructure before adding orchestration complexity

For an ADK and BigQuery implementation, we would start with a managed application runtime and isolated evaluation jobs. Kubernetes or dedicated model-serving infrastructure should follow demonstrated requirements for utilization, networking, or operational control—not the mere presence of an agent. Warehouse query cost and evaluation frequency may matter more initially than application compute.

Risks, Costs and Security

  • False confidence: Result matching validates observed outputs against fixtures, not every possible database state. Rubric-based assessment also needs calibration and human review for consequential failures.
  • Over-normalization: Aggressive coercion can erase meaningful differences in identifiers, precision, or ordering. Comparison policies need explicit tests. [1]
  • Data exposure: Query results, traces, and reference answers can contain sensitive information. Restrict access, minimize retained data, and define retention periods.
  • Prompt injection and excessive permissions: Treat retrieved content as untrusted and enforce authorization outside the model. Prompt injection remains an engineering concern in agent-based systems. [2]
  • Recurring operational cost: Budget for BigQuery execution, model calls, evaluation runs, observability, and fixture maintenance. Deterministic comparison removes one inference expense; it does not make the system inexpensive by itself.

The production goal is not SQL that looks right. It is a system whose permissions, results, explanations, and operating costs can be tested independently and controlled together.

Where Kimbodo Comes In

Kimbodo builds and operates this in production for businesses — see our AI Infrastructure & MLOps practice, or Estimate My Infrastructure.

Sources

  1. [1] Designing Custom Evaluation Metrics in ADK for NL2SQL Data Agents
  2. [2] Lenny's Podcast: Coding is solved—now what do we do? – Simon Willison

Leave a comment

0.0/5

Engineering Founded & Customer Focused

KIMBODO LLC. © 2026. All Rights Reserved.