Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Evidentlyai Evidently Legacy IsValidSQL Feature

From Leeroopedia
Revision as of 12:28, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Evidentlyai_Evidently_Legacy_IsValidSQL_Feature.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains ML Monitoring, Data Validation, SQL Analysis
Last Updated 2026-02-14 12:00 GMT

Overview

Provides a generated feature that validates whether each value in a specified text column is syntactically valid SQL.

Description

The IsValidSQL class extends ApplyColumnGeneratedFeature to apply a per-row validation check for SQL syntax. The validation is performed using the sqlvalidator library. The apply method first checks that the value is not None and is a string, then delegates to the is_valid_sql method.

The is_valid_sql method handles multi-statement SQL by splitting the input on semicolons. Each individual statement is trimmed of whitespace, and empty statements are skipped. Each non-empty statement is validated using sqlvalidator.format_sql. If any statement raises an exception, the entire value is considered invalid. The feature type is ColumnType.Categorical since the output is a boolean classification.

The class uses a display_name_template class variable set to "SQL Validity Check for {column_name}" which provides automatic display naming.

Usage

Use this feature when monitoring or evaluating LLM outputs or other text data that is expected to contain valid SQL queries. It supports multi-statement SQL separated by semicolons. Requires the sqlvalidator third-party package to be installed.

Code Reference

Source Location

Signature

class IsValidSQL(ApplyColumnGeneratedFeature):
    class Config:
        type_alias = "evidently:feature:IsValidSQL"

    __feature_type__: ClassVar = ColumnType.Categorical
    display_name_template: ClassVar = "SQL Validity Check for {column_name}"

    def __init__(self, column_name: str, display_name: Optional[str] = None): ...
    def apply(self, value: Any): ...
    def is_valid_sql(self, query: str) -> bool: ...

Import

from evidently.legacy.features.is_valid_sql_feature import IsValidSQL

I/O Contract

Inputs

Name Type Required Description
column_name str Yes Name of the text column in the DataFrame to validate as SQL
display_name Optional[str] No Custom display name for the feature (defaults to template-based name)

Outputs

Name Type Description
return bool (per row) True if the value contains valid SQL (all semicolon-separated statements are valid), False otherwise

Usage Examples

from evidently.legacy.features.is_valid_sql_feature import IsValidSQL

# Create the feature for a column named "query"
sql_feature = IsValidSQL(column_name="query")

# With a custom display name
sql_feature = IsValidSQL(column_name="generated_sql", display_name="Generated SQL Validity")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment