Skip to main content
Text-to-SQL metrics help you measure how well your AI systems generate SQL queries from natural language inputs. These metrics evaluate multiple dimensions of SQL generation quality—from syntactic correctness to security—helping you build reliable and safe Text-to-SQL applications. Use these metrics when you want to:
  • Validate that generated SQL queries are syntactically correct for your target database dialect.
  • Ensure generated queries only reference tables, columns, and data types that exist in your schema.
  • Verify that SQL queries accurately reflect the user’s natural language intent.
  • Protect against SQL injection attacks and malicious query patterns.
  • Detect performance anti-patterns that could impact database availability.
Below is a quick reference table of all Text-to-SQL metrics:
NameDescriptionSupported NodesWhen to UseExample Use Case
SQL CorrectnessEvaluates whether a generated SQL query is syntactically valid and adheres to the provided database schema.LLM spanWhen validating that generated SQL queries are grammatically correct and properly grounded in the database schema.A business intelligence assistant that translates user questions into SQL queries for a data warehouse.
SQL AdherenceEvaluates whether a generated SQL query semantically aligns with the user’s natural language intent.LLM spanWhen validating that generated SQL queries accurately reflect what the user requested.A data analytics assistant where users ask questions in natural language and expect accurate query results.
SQL InjectionDetects SQL injection attacks and security vulnerabilities in generated SQL queries.LLM spanWhen protecting against malicious inputs and ensuring generated SQL is safe to execute.A customer-facing data analytics chatbot that must prevent injection attacks from user inputs.
SQL EfficiencyEvaluates whether a generated SQL query is structured efficiently and avoids performance anti-patterns.LLM spanWhen validating that generated SQL queries won’t cause performance issues or resource exhaustion.A business intelligence platform where ad-hoc queries must not impact database availability.

Next steps