Filters allow you to ignore specific dbt entities for certain rules. A filter returns True if the item should be evaluated, and False if it should be ignored.
Using @rule_filter (Decorator)
Use the @rule_filter decorator on a function. The argument type annotation dictates the target entity.
from dbt_score import Model, RuleFilter, rule_filter
@rule_filter
def only_schema_x(model: Model) -> bool:
"""Only applies a rule to schema X."""
return model.schema.lower() == 'x'
Using RuleFilter (Class)
Inherit from RuleFilter and implement the evaluate method.
class SkipSchemaY(RuleFilter):
description = "Applies a rule to every schema but Y."
def evaluate(self, model: Model) -> bool:
return model.schema.lower() != 'y'
Applying filters to a rule
You can attach filters to a rule using the rule_filters argument in the @rule decorator.
@rule(rule_filters={only_schema_x()})
def models_in_x_follow_naming_standard(model: Model) -> RuleViolation | None:
# ... implementation
from dbt_score import Model, rule, RuleViolation
from my_project import only_schema_x
@rule(rule_filters={only_schema_x()})
def models_in_x_follow_naming_standard(model: Model) -> RuleViolation | None:
"""Models in schema X must follow the naming standard."""
if some_regex_fails(model.name):
return RuleViolation("Invalid model name.")