> For the complete documentation index, see [llms.txt](https://docs.snowkill.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.snowkill.net/condition/query-filters.md).

# Query Filters

Query filters are used in [conditions](/condition/built-in-conditions.md) to:

* narrow down the scope of affected queries
* narrow down the scope of queries which can be killed

Example usage:

```python
QueryFilter(
    # Include users with names with specific prefixes
    include_user_name=["ANALYST_*", "DATA_SCIENCE_*"],
    # Exclude user with specific name 
    exclude_user_name=["ANALYST_JOHN_DOE"],
)
```

```python
QueryFilter(
    # Include queries running on warehouses with specific suffixes
    include_warehouse=["*_SMALL_WH", "*_MEDIUM_WH"],
    # Include users with emails from specific org
    include_user_email=["*@myorg.com"]
)
```

```python
QueryFilter(
    # Exclude queries with comment "--no-kill" in SQL text
    exclude_sql_text=["*--no-kill"]
)
```

### Filter Arguments

* **include\_user\_name** (str|Pattern) - include users with names matching patterns
* **exclude\_user\_name** (str|Pattern) - exclude users with names matching patterns
* **include\_user\_login\_name** (str|Pattern) - include users with login names matching patterns
* **exclude\_user\_login\_name** (str|Pattern) - exclude users with login names matching patterns
* **include\_user\_email** (str|Pattern) - include users with emails matching patterns
* **exclude\_user\_email** (str|Pattern) - exclude users with emails matching patterns
* **include\_warehouse\_name** (str|Pattern) - include queries running on warehouses with names matching patterns
* **exclude\_warehouse\_name** (str|Pattern) - exclude queries running on warehouses with names matching patterns
* **include\_sql\_text** (str|Pattern) - include queries with SQL text matching patterns
* **exclude\_sql\_text** (str|Pattern) - exclude queries with SQL text matching patterns
* **include\_query\_tag** (str|Pattern) - include queries with Query Tag matching patterns
* **exclude\_query\_tag** (str|Pattern) - exclude queries with Query Tag matching patterns

### Usage notes

1. Individual patterns in one argument are combined with `OR`-logic. If at least one pattern returns true, the whole argument check returns true.
2. Multiple arguments are combined with `AND`-logic. All specified arguments should return true in order for query to match filter.
3. String patterns are interpreted as basic [Unix filename patterns](https://docs.python.org/3/library/fnmatch.html) , with `*` matching everything and `?` matching single character.
4. For more complex cases, it is allowed to use free-form `Pattern` objects produced by [`re.compile`](https://docs.python.org/3/library/re.html#re.compile) function. Such patterns should match the full string.
