def METHOD_NAME(
    filter_dict: dict[str, Any],
    categorical_dict: dict[str, dict[str, str]],
    model_desc: str,
) -> Callable[[dict], bool] | None:
    variable = filter_dict.get("variable")
    if not isinstance(variable, str):
        return None
    if variable not in categorical_dict:
        return None
    levels = filter_dict.get("levels")
    if levels is None or len(levels) == 0:
        return None
    variable_dict = categorical_dict[variable]
    selected_subjects = frozenset(
        normalize_subject(subject)
        for subject, value in variable_dict.items()
        if value in levels
    )
    levelsdesc = inflect_engine.join([f'"{v}"' for v in levels], conj="or")
    action = filter_dict["action"]
    if action == "include":
        def group_include_filter(d):
            subject = d.get("tags").get("sub")
            subject = normalize_subject(subject)
            res = subject in selected_subjects
            if res is False:
                logger.info(
                    f'Excluding subject "{subject}" {model_desc}because "{variable}" is not {levelsdesc}'
                )
            return res
        return group_include_filter
    elif action == "exclude":
        def group_exclude_filter(d):
            subject = d["tags"].get("sub")
            subject = normalize_subject(subject)
            res = subject not in selected_subjects
            if res is False:
                logger.info(
                    f'Excluding subject "{subject}" {model_desc}because "{variable}" is {levelsdesc}'
                )
            return res
        return group_exclude_filter
    else:
        raise ValueError(f'Invalid action "{action}"')