def validate(self, spans: List[Tuple[str, int, int]]):
        """Validates the alignment of span boundaries and tokens.

        Args:
            spans: A list of spans.

        Raises:
            ValueError: If a span is invalid, or if a span is not aligned with the tokens.
        """
        not_valid_spans_errors, misaligned_spans_errors = [], []

        for span in spans:
            char_start, char_end = span[1], span[2]
            if char_end - char_start < 1:
                not_valid_spans_errors.append(span)
            elif None in (
                self._start_to_token_idx.get(char_start),
                self._end_to_token_idx.get(char_end),
            ):
                span_str = self.text[char_start:char_end]
                message = f"{span} - {repr(span_str)}"
                misaligned_spans_errors.append(message)

        if not_valid_spans_errors or misaligned_spans_errors:
            message = ""
            if not_valid_spans_errors:
                message += f"Following entity spans are not valid: {not_valid_spans_errors}\n"

            if misaligned_spans_errors:
                spans = "\n".join(misaligned_spans_errors)
                message += "Following entity spans are not aligned with provided tokenization\n"
                message += f"Spans:\n{spans}\n"
                message += f"Tokens:\n{self.tokens}"

            raise ValueError(message)
Validates the alignment of span boundaries and tokens.

        Args:
            spans: A list of spans.

        Raises:
            ValueError: If a span is invalid, or if a span is not aligned with the tokens.
        
argilla-v1/src/argilla_v1/utils/span_utils.py