Skip to content

Core API

BaseSignal

Bases: ABC

Abstract base class for all content detection signals.

A 'Signal' is a specialized detector that analyzes content of a specific type (text, image, audio) and produces a probabilistic assessment of whether it is AI-generated.

Subclasses must implement
  • name: Unique string identifier.
  • dtype: Input data type supported.
  • run(): The core detection logic.
Source code in veridex/core/signal.py
class BaseSignal(ABC):
    """
    Abstract base class for all content detection signals.

    A 'Signal' is a specialized detector that analyzes content of a specific type (text, image, audio)
    and produces a probabilistic assessment of whether it is AI-generated.

    Subclasses must implement:
        - `name`: Unique string identifier.
        - `dtype`: Input data type supported.
        - `run()`: The core detection logic.
    """

    @property
    @abstractmethod
    def name(self) -> str:
        """
        Unique identifier for the signal.

        Returns:
            str: A short, snake_case name (e.g., 'zlib_entropy', 'perplexity').
        """
        pass

    @property
    @abstractmethod
    def dtype(self) -> str:
        """
        Data type this signal operates on.

        Returns:
            str: One of 'text', 'image', 'audio', 'video'.
        """
        pass

    @abstractmethod
    def run(self, input_data: Any) -> DetectionResult:
        """
        Execute the detection logic on the provided input.

        Args:
            input_data (Any): The content to analyze. Type should match `self.dtype` expectations:
                - 'text': `str`
                - 'image': `str` (path), `PIL.Image.Image`, or `numpy.ndarray`
                - 'audio': `str` (path) or `numpy.ndarray` (waveform)
                - 'video': `str` (path)

        Returns:
            DetectionResult: The result containing score, confidence, and metadata.
        """
        pass

    def check_dependencies(self) -> None:
        """
        Optional hook to check if required heavy dependencies are installed.

        This is called before expensive operations or at initialization time.

        Raises:
            ImportError: If required extra dependencies (e.g., torch, transformers) are missing.
        """
        pass

    def detect(self, input_data: Any) -> DetectionResult:
        """
        Public alias for `run()`.

        It is recommended to use this method instead of `run()` directly, as it may include
        future pre/post-processing steps.

        Args:
            input_data (Any): The content to analyze.

        Returns:
            DetectionResult: The detection result.
        """
        return self.run(input_data)

name abstractmethod property

Unique identifier for the signal.

Returns:

Name Type Description
str str

A short, snake_case name (e.g., 'zlib_entropy', 'perplexity').

dtype abstractmethod property

Data type this signal operates on.

Returns:

Name Type Description
str str

One of 'text', 'image', 'audio', 'video'.

run(input_data) abstractmethod

Execute the detection logic on the provided input.

Parameters:

Name Type Description Default
input_data Any

The content to analyze. Type should match self.dtype expectations: - 'text': str - 'image': str (path), PIL.Image.Image, or numpy.ndarray - 'audio': str (path) or numpy.ndarray (waveform) - 'video': str (path)

required

Returns:

Name Type Description
DetectionResult DetectionResult

The result containing score, confidence, and metadata.

Source code in veridex/core/signal.py
@abstractmethod
def run(self, input_data: Any) -> DetectionResult:
    """
    Execute the detection logic on the provided input.

    Args:
        input_data (Any): The content to analyze. Type should match `self.dtype` expectations:
            - 'text': `str`
            - 'image': `str` (path), `PIL.Image.Image`, or `numpy.ndarray`
            - 'audio': `str` (path) or `numpy.ndarray` (waveform)
            - 'video': `str` (path)

    Returns:
        DetectionResult: The result containing score, confidence, and metadata.
    """
    pass

check_dependencies()

Optional hook to check if required heavy dependencies are installed.

This is called before expensive operations or at initialization time.

Raises:

Type Description
ImportError

If required extra dependencies (e.g., torch, transformers) are missing.

Source code in veridex/core/signal.py
def check_dependencies(self) -> None:
    """
    Optional hook to check if required heavy dependencies are installed.

    This is called before expensive operations or at initialization time.

    Raises:
        ImportError: If required extra dependencies (e.g., torch, transformers) are missing.
    """
    pass

detect(input_data)

Public alias for run().

It is recommended to use this method instead of run() directly, as it may include future pre/post-processing steps.

Parameters:

Name Type Description Default
input_data Any

The content to analyze.

required

Returns:

Name Type Description
DetectionResult DetectionResult

The detection result.

Source code in veridex/core/signal.py
def detect(self, input_data: Any) -> DetectionResult:
    """
    Public alias for `run()`.

    It is recommended to use this method instead of `run()` directly, as it may include
    future pre/post-processing steps.

    Args:
        input_data (Any): The content to analyze.

    Returns:
        DetectionResult: The detection result.
    """
    return self.run(input_data)

DetectionResult

Bases: BaseModel

Standardized output model for all detection signals.

This model encapsulates the result of a detection signal, providing a normalized score, a confidence level, and optional metadata or error information.

Attributes:

Name Type Description
score float

Normalized probability score indicating AI-likelihood. Range [0.0, 1.0], where 0.0 is confidently Human and 1.0 is confidently AI.

confidence float

A measure of the reliability of the score estimation. Range [0.0, 1.0], where 1.0 means the signal is fully confident in its assessment.

Confidence interpretation: - 0.0-0.3: Low confidence (heuristics, untrained models, errors) - 0.4-0.6: Moderate confidence (statistical methods, limited data) - 0.7-0.9: High confidence (trained models with good predictions) - 0.9-1.0: Very high confidence (strong model predictions, clear patterns)

For model-based signals, confidence is extracted from model outputs (softmax probabilities, margins, etc.). For heuristic signals, confidence reflects empirical reliability.

metadata Dict[str, Any]

Dictionary containing signal-specific intermediate values, features, or debug information used to derive the score.

error Optional[str]

Error message if the signal failed to execute. If present, score and confidence should be treated as invalid or default.

Example
result = DetectionResult(
    score=0.95,
    confidence=0.98,
    metadata={"burstiness": 12.5, "perplexity": 5.2}
)
if result.score > 0.5:
    print("Likely AI-generated")
Source code in veridex/core/signal.py
class DetectionResult(BaseModel):
    """
    Standardized output model for all detection signals.

    This model encapsulates the result of a detection signal, providing a normalized score,
    a confidence level, and optional metadata or error information.

    Attributes:
        score (float): Normalized probability score indicating AI-likelihood.
            Range [0.0, 1.0], where 0.0 is confidently Human and 1.0 is confidently AI.
        confidence (float): A measure of the reliability of the score estimation.
            Range [0.0, 1.0], where 1.0 means the signal is fully confident in its assessment.

            Confidence interpretation:
            - 0.0-0.3: Low confidence (heuristics, untrained models, errors)
            - 0.4-0.6: Moderate confidence (statistical methods, limited data)
            - 0.7-0.9: High confidence (trained models with good predictions)
            - 0.9-1.0: Very high confidence (strong model predictions, clear patterns)

            For model-based signals, confidence is extracted from model outputs (softmax probabilities,
            margins, etc.). For heuristic signals, confidence reflects empirical reliability.

        metadata (Dict[str, Any]): Dictionary containing signal-specific intermediate values,
            features, or debug information used to derive the score.
        error (Optional[str]): Error message if the signal failed to execute.
            If present, `score` and `confidence` should be treated as invalid or default.

    Example:
        ```python
        result = DetectionResult(
            score=0.95,
            confidence=0.98,
            metadata={"burstiness": 12.5, "perplexity": 5.2}
        )
        if result.score > 0.5:
            print("Likely AI-generated")
        ```
    """
    score: float = Field(..., ge=0.0, le=1.0, description="Normalized score indicating AI probability. 0=Human, 1=AI.")
    confidence: float = Field(..., ge=0.0, le=1.0, description="Reliability of the score estimation.")
    metadata: Dict[str, Any] = Field(default_factory=dict, description="Additional signal-specific information.")
    error: Optional[str] = Field(None, description="Error message if the signal failed to execute.")