def validate_explanation(explanation: str | None) -> str | None:
        """Validate the explanation string.

        This method validates explanation strings.

        Args:
            explanation (``str`` | ``None``): Input explanation string.

        Returns:
            ``str`` | ``None``: Validated explanation string, or None.

        Raises:
            TypeError: If ``explanation`` is not a string.

        Example:
            >>> from anomalib.data.validators import ImageValidator
            >>> explanation = "The image has a crack on the wall."
            >>> validated = ImageValidator.validate_explanation(explanation)
            >>> validated == explanation
            True
        """
        if explanation is None:
            return None
        if not isinstance(explanation, str):
            msg = f"Explanation must be a string, got {type(explanation)}."
            raise TypeError(msg)
        return explanation
Validate the explanation string.

        This method validates explanation strings.

        Args:
            explanation (``str`` | ``None``): Input explanation string.

        Returns:
            ``str`` | ``None``: Validated explanation string, or None.

        Raises:
            TypeError: If ``explanation`` is not a string.

        Example:
            >>> from anomalib.data.validators import ImageValidator
            >>> explanation = "The image has a crack on the wall."
            >>> validated = ImageValidator.validate_explanation(explanation)
            >>> validated == explanation
            True
        
src/anomalib/data/validators/torch/image.py