# Filters in Tests

Filters can also be used to specify a sub-selection of rows in runs you would like to include in the test computation.

For example, our goal could be to create a test that asserts that, for rows where the loc column is ‘NY’, the absolute difference of means of the correct churn predictions is <= 0.2 between baseline and experiment runs.

We will walk through how this can be accomplished:

\
1\. Navigate to the Project Detail page and click on “Configure Tests”.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfL9umLBzekS_o0iKJZ6rz5ffF0k6bnM_csnbZz5duin4r_ZiKixCduunrby7XDQKTEKzdZQPiDfoF3y53cT6pJD6Fv5gLEUwAgZsF_Iu5YSiNm5082HN33O4Ys-XoQUmin8PXioHdevfRKMr-VhOh30zLC?key=rITDctX4nVqKraPSKOD6NQ" alt=""><figcaption></figcaption></figure>

2. Click Add Test on the Test Configuration page. Don’t forget to also set a baseline run for automated test configuration.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeFkQzTHFmHtfCCtW9wbOJu2KnJ0sFfcgK08oAXViz0PrMHLEe0Nu7WdSCjXBP-sn09C1mqdKbRsAZmmFiB0I61DxU3mugBlPe5pwFPB25I2EZRsVuXDCzr81yancxSIN7WNerVOrx4eAlAaIg1L-CB9M5w?key=rITDctX4nVqKraPSKOD6NQ" alt=""><figcaption></figcaption></figure>

3. Create the test with the filter specified on the baseline and experiment run.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdOHWNqmXs7InU7g3n3PEFznh2rwUPc9ML937vRLCAHUwuO0iJnrfcU-helDES7uZsJn3Agzy7igOHR7k5D-afGkJBQsgB91MjtRpEEmqPql8P35ezRIVGCWEWRPz5A8Efa3sZdkAnAQ4fuXoTd80KPrf2A?key=rITDctX4nVqKraPSKOD6NQ" alt=""><figcaption></figcaption></figure>

Filter for the baseline Run:

```
equal_to({BASELINE}.loc, 'NY')
```

Filter for the experiment Run:

```
equal_to({EXPERIMENT}.loc, 'NY')
```

\
4\. You can now see the new test in the Test Configuration Page. When new data is uploaded, this test will automatically run and compare the new run (as experiment) against the selected baseline run.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdlVn44UrRHrz6LgrYu7shusb4R8SfKwzO3VkaTvel8ihClYQalmBm05l3Iq9r1hLLRoK9iA3WjtKM9BFMaKK_XZ_57qlZPZ6_5UTZKRnc0IxPhM8wDU-x0WEYIsMmLpyEMhdYq7kKe1jvQSu0eOQhLHMwq?key=rITDctX4nVqKraPSKOD6NQ" alt=""><figcaption></figcaption></figure>

When new run data is uploaded, this test will run automatically and use the defined filters to sub-select for the rows that have the loc column equal to ‘NY’.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfOxEhCjs_BPRsJe0nRQbO3Rn1DClwuqyRRpuaTp9QVrpDW7qMLj93Xy8w4jpFilcAXBsv2F4KEiWp2VKEC7SlPiY61fvdeV57ss_HxcWCon_6RkTMVcEbLCg5fXPc9FLykRPRdAxx8xe5_Z7qTmENtHqwv?key=rITDctX4nVqKraPSKOD6NQ" alt=""><figcaption></figcaption></figure>

The full Test Spec in JSON format is shown below.

```json
{
    "name": "abs diff of mean of correct churn preds of NY users is within 0.2",
    "statistic_name": "abs_diff_mean",
    "statistic_params": {},
    "assertions": [
        {
            "name": "less_than_or_equal_to",
            "params": {
                "other": 0.2
            },
        }
    ],
    "statistic_inputs": [
        {
            "select_query_template": {
                "select": "{BASELINE}.pred_correct",
                "filter": "equal_to({BASELINE}.loc, 'NY')"
            }
        },
        {
            "select_query_template": {
                "select": "{EXPERIMENT}.pred_correct",
                "filter": "equal_to({EXPERIMENT}.loc, 'NY')"
            }
        },
    ],
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.dbnl.com/v0.20.x/using-distributional/testing/using-filters/filters-in-tests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
