SQL Based Rules

SQL-Based Validation Rules give you full SQL pushdown for record-level data quality checks. Instead of Telmai's rule expression builder, you write a standard SQL query directly against your data source. Telmai executes it natively on the compute engine (Snowflake, BigQuery, Databricks, etc.) and ingests the results.
This is ideal when:
Your validation logic is complex and already expressed in SQL
You need to join across multiple tables or use warehouse-specific functions
You want to reuse existing SQL-based data quality checks without rewriting them in DSL
How It Works
You provide a SQL query (Q) that Telmai executes against your data source. The query must return a specific output schema. Telmai reads the results and computes the Correctness metric as the percentage of records where is_valid = 1.
For example, for a table with 1M rows: if 50,000 records return is_valid = 0, the Correctness score is 95%.
Query Structure
Your SQL query must return columns in the following exact order:
is_valid
Integer
Yes
Validation result. 1 = valid, 0 = invalid.
record_id
String or Integer
No
The unique identifier for the record. Used to surface failing records in the UI.
record_id_name
String
No
A static label for the identifier field. Used as metadata in incident drill-downs.
Example Queries
Minimal — validation result only
With record identifier
Full output — with metadata label
Cross-table join validation
Conditional logic with warehouse functions
Creating a SQL-Based Rule
Navigate to Alerting Monitors and click New Monitor
Choose SQL-Based Rule as the monitor type
Enter a monitor name and optional description
Write your SQL query following the required output schema above
Validate and save the rule
Last updated