---
title: "Doing data quality checks using the SQLCheckOperator"
description: "How to use SQLCheckOperator to verify that the database contains an expected number of rows"
author: "Bartosz Mikulski"
author_bio: "Principal AI Engineer & MLOps Architect. I bridge the gap between \"it works in a notebook\" and \"it works for 200 million users.\""
author_url: https://mikulskibartosz.name
author_linkedin: https://www.linkedin.com/in/mikulskibartosz/
author_github: https://github.com/mikulskibartosz
canonical_url: https://mikulskibartosz.name/data-quality-checks-using-sqlcheckoperator
---

SQLCheckOperator is an Airflow operator that executes a SQL query, expects to receive a single row in the response, and attempts to cast every value in the row to a boolean. It succeeds when all returned values can be cast to true, so the query may return those values:

* a boolean `True`

* a non-zero numeric value (including negative values!)

* a non-empty string

* a non-empty list, set, or dictionary

In addition to failing when any of the values is `False`, the SQLCheckOperator operator also fails when the query returns no rows.

For example, we can use that operator to check the count of values in a table:

```python
from airflow.operators.sql import SQLCheckOperator

operator = SQLCheckOperator(
    {% raw %} sql="SELECT COUNT(*) FROM some_table WHERE some_column='{{ yesterday_ds_nodash }}'"{% endraw %}
)
```

