@staticmethod
def _sparsity_validator(value, port):
    """
        Helper function to validate the 'sparsity' input.
        """
    if value:
        sparsity_value = value.value
        allowed_values = ['as_input', 'sparse', 'dense']
        if sparsity_value not in allowed_values:
            return (
                f"Invalid sparsity value '{sparsity_value}', must be one of {allowed_values}"
                )
    return None
