For the complete documentation index, see llms.txt. This page is also available as Markdown.

Valid SQL

Check correctness of SQL outputs from AI models. Prevent invalid or broken database statements.

Objective Validates if the text is a valid SQL statement, ensuring executable and accurate queries.

Interpretation A higher score indicates the text is not valid SQL. A lower (or zero) score indicates the query is valid.

Code Execution

metrics = [
    {
        "name": "Valid SQL",
        "config": {
            "model": "gpt-4o-mini",
            "provider": "openai"
        },
        "column_name": "your-column-identifier",
        "schema_mapping": schema_mapping
    }
]

Example

  • Prompt: “Provide a valid SQL query to select all records from the ‘users’ table.”

  • Context: “Must be syntactically correct.”

  • Response: SELECT * FROM users

  • Metric Output: {"score": 1, "reason": "Invalid SQL (missing semicolon in strict syntax)."}

Last updated

Was this helpful?