Hi, <@U088WCP3B4P>, is there any way to exclude on...
# ask-elementary-ai
м
Hi, @kapa.ai, is there any way to exclude only one column from the analysis in the model? For example, exclude the internal_id field, for example, in the test: - elementary.volume_anomalies: tags: ["elementary"] - elementary.all_columns_anomalies: tags: ["elementary"] seasonality: from day to week
k
A message from kapa.ai
Yes, you can exclude a specific column (such as
internal_id
) from the
elementary.all_columns_anomalies
test by using the
exclude_prefix
or
exclude_regexp
parameters. For a single column, the simplest way is to use
exclude_prefix
if your column name has a unique prefix, or
exclude_regexp
for an exact or partial match. For example, to exclude only the
internal_id
column, you can use:
Copy code
yaml models:   - name: your_model_name     tests:       - elementary.all_columns_anomalies:           exclude_regexp: "^internal_id$"
This configuration will ensure that only the
internal_id
column is excluded from the analysis, while all other columns are still monitored. The
exclude_regexp
parameter matches the column name exactly in this case. Alternatively, if you want to exclude columns by prefix (e.g., all columns starting with
internal_
), you could use:
Copy code
yaml       - elementary.all_columns_anomalies:           exclude_prefix: "internal_"
But for a single column, the regex approach is more precise. Note that
exclude_prefix
and
exclude_regexp
are only available for the
all_columns_anomalies
test, not for
volume_anomalies
or other tests [exclude_regexp documentation](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/exclude_regexp) [exclude_prefix documentation](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/exclude_prefix). If you want to set the
seasonality
parameter (e.g., from day to week), you can add it as follows:
Copy code
yaml       - elementary.all_columns_anomalies:           exclude_regexp: "^internal_id$"           seasonality: day_of_week
Let me know if you need an example for another test or further clarification!
м
it's very strange @kapa.ai, but my test still returns an error models: - name: test_upload_on_day description: Middle layer model config: elementary: timestamp_column: report_day tests: - elementary.volume_anomalies: tags: ["elementary"] - elementary.all_columns_anomalies: tags: ["elementary"] exclude_regexp: "^internal_id$" seasonality: day_of_week Failure in test elementary_all_columns_anomalies_test_upload_on_day__internal_id___day_of_week (models\middle\test_upload_on_day.yml)
k
A message from kapa.ai
Based on the knowledge sources, your configuration for excluding the
internal_id
column using
exclude_regexp: "^internal_id$"
in the
elementary.all_columns_anomalies
test is correct and should work for excluding a single column by exact name match [exclude_regexp documentation](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/exclude_regexp). However, there are a few important caveats and known issues: 1. YAML Indentation and Syntax: Ensure your YAML indentation is correct. The
exclude_regexp
parameter should be at the same level as other test parameters. 2. Test Name Still References Excluded Column: Even when a column is excluded, the generated dbt test name may still include the column name due to how dbt constructs test names. This does not necessarily mean the column is being tested, but it can be confusing [Slack discussion](https://slack.com/archives/C02CTC89LAX/p1650985870725969). 3. dbt Package Version: The ability to exclude columns using
exclude_regexp
was added in version 0.3.14. If you are using an older version, this feature will not work. Please ensure you are using at least version 0.3.14 [Slack discussion](https://slack.com/archives/C02CTC89LAX/p1650985870725969). 4. Known Limitation – Only One Prefix/Regexp: Only one
exclude_prefix
or
exclude_regexp
can be used at a time. If you need to exclude multiple columns, you must use a regular expression that matches all of them, e.g.,
exclude_regexp: "^(internal_id|other_column)$"
 [Slack discussion](https://slack.com/archives/C02CTC89LAX/p1650985870725969). 5. Test Still Fails on Excluded Column: If the test is still failing on
internal_id
, it could be due to: - A typo in the column name. - The column is not being matched by the regex (double-check the exact column name in your database). - The dbt package version is too old. - There is a bug or edge case in the implementation (as reported by other users) [Slack discussion](https://slack.com/archives/C02CTC89LAX/p1697205851749239). What you can try: - Double-check the spelling and case of
internal_id
in your model. - Make sure you are using dbt-elementary version 0.3.14 or newer. - Try a broader regex, e.g.,
exclude_regexp: "internal_id"
(without the anchors) to see if it matches. - If you are still seeing the error, it may be a bug. Other users have reported similar issues, and the workaround is to use
exclude_regexp
with a pattern that matches the column, or to define the test at the column level and exclude the problematic column [Slack discussion](https://slack.com/archives/C02CTC89LAX/p1697205851749239). If none of these resolve the issue, it is likely a bug, and you may want to open a ticket on the Elementary GitHub repository as other users have done. Let me know if you need help with a specific regex pattern or further troubleshooting!
м
@kapa.ai, my version Elementary 0.19.5, Check if I have the right format. models: - name: test_upload_on_day description: Middle layer model config: elementary: timestamp_column: report_day tests: - elementary.volume_anomalies: tags: ["elementary"] - elementary.all_columns_anomalies: tags: ["elementary"] exclude_regexp: "^internal_id$" seasonality: day_of_week
k
A message from kapa.ai
Your YAML format is almost correct, but there are indentation issues that could cause problems with dbt and Elementary. The parameters under each test should be indented properly. Here’s the corrected format based on the knowledge sources:
Copy code
yaml models:   - name: test_upload_on_day     description: Middle layer model     config:       elementary:         timestamp_column: report_day     tests:       - elementary.volume_anomalies:           tags: ["elementary"]       - elementary.all_columns_anomalies:           tags: ["elementary"]           exclude_regexp: "^internal_id$"           seasonality: day_of_week
Key points: - The parameters (
tags
,
exclude_regexp
,
seasonality
) should be indented two spaces under the test name. - Your use of
exclude_regexp: "^internal_id$"
is correct for excluding a single column by exact name [exclude_regexp documentation](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/exclude_regexp). - The
seasonality
parameter is also correctly placed. Version compatibility: You mentioned you are using Elementary version 0.19.5. The knowledge sources confirm that
exclude_regexp
is supported in recent versions, but the feature was introduced in version 0.3.14 of the dbt package. If you are referring to the dbt package version, ensure it is at least 0.3.14 for this feature to work as expected [Slack discussion](https://slack.com/archives/C02CTC89LAX/p1650985870725969). If you still encounter issues after correcting the indentation and confirming the version, it may be a bug or an edge case as reported by other users. Let me know if you need further help!
м
@@kapa.ai,Elementary applies the test to all columns except: timestamp_column, if specified dbt_valid_from, dbt_valid_to (if the type is SCD) sometimes there are no columns if they are manually defined in macros (but this is not your case) What can I do now: Split the test manually — eliminate unnecessary columns It can replace all_columns_anomalies with multiple column_anomalies calls for the desired columns, except INTERNAL_ID
k
A message from kapa.ai
Yes, your understanding is correct and aligns with the guidance from the knowledge sources. If you want to exclude specific columns (like
internal_id
) from anomaly detection, and the
exclude_regexp
or
exclude_prefix
options are not working as expected or are too broad, you can manually split the test by applying
elementary.column_anomalies
only to the columns you want to monitor. This approach gives you full control over which columns are tested. Here’s how you can do it:
Copy code
yaml models:   - name: test_upload_on_day     config:       elementary:         timestamp_column: report_day     columns:       - name: column1         tests:           - elementary.column_anomalies:               # your desired monitors here       - name: column2         tests:           - elementary.column_anomalies:               # your desired monitors here       # Do NOT include internal_id here
This method is explicitly mentioned as a workaround in the knowledge sources, especially when you want to avoid running tests on certain columns and the built-in exclusion parameters are insufficient or problematic [Slack discussion](https://slack.com/archives/C02CTC89LAX/p1650985870725969). So, replacing
all_columns_anomalies
with multiple
column_anomalies
tests for only the desired columns (excluding
internal_id
) is a valid and supported approach.