Skip to content

safety

default_safety_rules module-attribute

default_safety_rules = SafetyRules(
    should_censor_nsfw=True,
    should_censor_hate_speech=True,
    should_censor_violent=True,
    should_censor_self_harm=True,
)

default_image_safety_rules module-attribute

default_image_safety_rules = SafetyRules(
    should_censor_nsfw=True,
    should_censor_hate_speech=True,
    should_censor_violent=True,
    should_censor_self_harm=True,
)

default_text_safety_rules module-attribute

default_text_safety_rules = SafetyRules(
    should_censor_nsfw=True,
    should_censor_hate_speech=True,
    should_censor_violent=True,
    should_censor_self_harm=True,
)

SafetyResult

Bases: BaseModel

A model representing the result of a safety check.

Source code in horde_sdk/safety.py
class SafetyResult(BaseModel):
    """A model representing the result of a safety check."""

    is_nsfw: bool
    """Indicates if the content is NSFW (Not Safe For Work)."""

    nsfw_likelihood: float | None = None
    """A float representing the likelihood that the content is NSFW, typically between 0.0 and 1.0."""

    is_csam: bool | None = None
    """Indicates if the content is CSAM."""

    csam_likelihood: float | None = None
    """A float representing the likelihood that the content is CSAM, typically between 0.0 and 1.0."""

    is_hate_speech: bool | None = None
    """Indicates if the content is hate speech."""

    hate_speech_likelihood: float | None = None
    """A float representing the likelihood that the content is hate speech, typically between 0.0 and 1.0."""

    is_violent: bool | None = None
    """Indicates if the content is violent."""

    violent_likelihood: float | None = None
    """A float representing the likelihood that the content is violent, typically between 0.0 and 1.0."""

    is_self_harm: bool | None = None
    """Indicates if the content promotes self-harm."""

    self_harm_likelihood: float | None = None
    """A float representing the likelihood that the content promotes self-harm, typically between 0.0 and 1.0."""

is_nsfw instance-attribute

is_nsfw: bool

Indicates if the content is NSFW (Not Safe For Work).

nsfw_likelihood class-attribute instance-attribute

nsfw_likelihood: float | None = None

A float representing the likelihood that the content is NSFW, typically between 0.0 and 1.0.

is_csam class-attribute instance-attribute

is_csam: bool | None = None

Indicates if the content is CSAM.

csam_likelihood class-attribute instance-attribute

csam_likelihood: float | None = None

A float representing the likelihood that the content is CSAM, typically between 0.0 and 1.0.

is_hate_speech class-attribute instance-attribute

is_hate_speech: bool | None = None

Indicates if the content is hate speech.

hate_speech_likelihood class-attribute instance-attribute

hate_speech_likelihood: float | None = None

A float representing the likelihood that the content is hate speech, typically between 0.0 and 1.0.

is_violent class-attribute instance-attribute

is_violent: bool | None = None

Indicates if the content is violent.

violent_likelihood class-attribute instance-attribute

violent_likelihood: float | None = None

A float representing the likelihood that the content is violent, typically between 0.0 and 1.0.

is_self_harm class-attribute instance-attribute

is_self_harm: bool | None = None

Indicates if the content promotes self-harm.

self_harm_likelihood class-attribute instance-attribute

self_harm_likelihood: float | None = None

A float representing the likelihood that the content promotes self-harm, typically between 0.0 and 1.0.

TextSafetyResult

Bases: SafetyResult

A model representing the result of a text safety check.

Source code in horde_sdk/safety.py
class TextSafetyResult(SafetyResult):
    """A model representing the result of a text safety check."""

is_nsfw instance-attribute

is_nsfw: bool

Indicates if the content is NSFW (Not Safe For Work).

nsfw_likelihood class-attribute instance-attribute

nsfw_likelihood: float | None = None

A float representing the likelihood that the content is NSFW, typically between 0.0 and 1.0.

is_csam class-attribute instance-attribute

is_csam: bool | None = None

Indicates if the content is CSAM.

csam_likelihood class-attribute instance-attribute

csam_likelihood: float | None = None

A float representing the likelihood that the content is CSAM, typically between 0.0 and 1.0.

is_hate_speech class-attribute instance-attribute

is_hate_speech: bool | None = None

Indicates if the content is hate speech.

hate_speech_likelihood class-attribute instance-attribute

hate_speech_likelihood: float | None = None

A float representing the likelihood that the content is hate speech, typically between 0.0 and 1.0.

is_violent class-attribute instance-attribute

is_violent: bool | None = None

Indicates if the content is violent.

violent_likelihood class-attribute instance-attribute

violent_likelihood: float | None = None

A float representing the likelihood that the content is violent, typically between 0.0 and 1.0.

is_self_harm class-attribute instance-attribute

is_self_harm: bool | None = None

Indicates if the content promotes self-harm.

self_harm_likelihood class-attribute instance-attribute

self_harm_likelihood: float | None = None

A float representing the likelihood that the content promotes self-harm, typically between 0.0 and 1.0.

ImageSafetyResult

Bases: SafetyResult

A model representing the result of an image safety check.

Source code in horde_sdk/safety.py
class ImageSafetyResult(SafetyResult):
    """A model representing the result of an image safety check."""

    is_csam: bool
    """Indicates if the content is CSAM."""

is_csam instance-attribute

is_csam: bool

Indicates if the content is CSAM.

is_nsfw instance-attribute

is_nsfw: bool

Indicates if the content is NSFW (Not Safe For Work).

nsfw_likelihood class-attribute instance-attribute

nsfw_likelihood: float | None = None

A float representing the likelihood that the content is NSFW, typically between 0.0 and 1.0.

csam_likelihood class-attribute instance-attribute

csam_likelihood: float | None = None

A float representing the likelihood that the content is CSAM, typically between 0.0 and 1.0.

is_hate_speech class-attribute instance-attribute

is_hate_speech: bool | None = None

Indicates if the content is hate speech.

hate_speech_likelihood class-attribute instance-attribute

hate_speech_likelihood: float | None = None

A float representing the likelihood that the content is hate speech, typically between 0.0 and 1.0.

is_violent class-attribute instance-attribute

is_violent: bool | None = None

Indicates if the content is violent.

violent_likelihood class-attribute instance-attribute

violent_likelihood: float | None = None

A float representing the likelihood that the content is violent, typically between 0.0 and 1.0.

is_self_harm class-attribute instance-attribute

is_self_harm: bool | None = None

Indicates if the content promotes self-harm.

self_harm_likelihood class-attribute instance-attribute

self_harm_likelihood: float | None = None

A float representing the likelihood that the content promotes self-harm, typically between 0.0 and 1.0.

SafetyRules

A class representing the rules for content safety checks.

Source code in horde_sdk/safety.py
class SafetyRules:
    """A class representing the rules for content safety checks."""

    should_censor_nsfw: bool = True
    """Indicates whether NSFW content should be censored."""

    should_censor_hate_speech: bool = True
    """Indicates whether hate speech content should be censored."""

    should_censor_violent: bool = True
    """Indicates whether violent content should be censored."""

    should_censor_self_harm: bool = True
    """Indicates whether self-harm content should be censored."""

    def should_censor(self, safety_result: SafetyResult) -> bool:
        """Determine if the content should be censored based on the safety result.

        Args:
            safety_result (SafetyResult): The result of the safety check.

        Returns:
            bool: True if the content should be censored, False otherwise.
        """
        if safety_result.is_csam:
            return True

        if safety_result.is_nsfw and self.should_censor_nsfw:
            return True

        if safety_result.is_hate_speech and self.should_censor_hate_speech:
            return True

        if safety_result.is_violent and self.should_censor_violent:
            return True

        return bool(safety_result.is_self_harm and self.should_censor_self_harm)

    def __init__(
        self,
        should_censor_nsfw: bool = True,
        should_censor_hate_speech: bool = True,
        should_censor_violent: bool = True,
        should_censor_self_harm: bool = True,
    ) -> None:
        """Initialize the SafetyRules with optional parameters to set censorship preferences.

        Args:
        should_censor_nsfw (bool): Whether to censor NSFW content. Defaults to True.
        should_censor_hate_speech (bool): Whether to censor hate speech content. Defaults to True.
        should_censor_violent (bool): Whether to censor violent content. Defaults to True.
        should_censor_self_harm (bool): Whether to censor self-harm content. Defaults to True.
        """
        self.should_censor_nsfw = should_censor_nsfw
        self.should_censor_hate_speech = should_censor_hate_speech
        self.should_censor_violent = should_censor_violent
        self.should_censor_self_harm = should_censor_self_harm

should_censor_nsfw class-attribute instance-attribute

should_censor_nsfw: bool = should_censor_nsfw

Indicates whether NSFW content should be censored.

should_censor_hate_speech class-attribute instance-attribute

should_censor_hate_speech: bool = should_censor_hate_speech

Indicates whether hate speech content should be censored.

should_censor_violent class-attribute instance-attribute

should_censor_violent: bool = should_censor_violent

Indicates whether violent content should be censored.

should_censor_self_harm class-attribute instance-attribute

should_censor_self_harm: bool = should_censor_self_harm

Indicates whether self-harm content should be censored.

should_censor

should_censor(safety_result: SafetyResult) -> bool

Determine if the content should be censored based on the safety result.

Parameters:

  • safety_result (SafetyResult) –

    The result of the safety check.

Returns:

  • bool ( bool ) –

    True if the content should be censored, False otherwise.

Source code in horde_sdk/safety.py
def should_censor(self, safety_result: SafetyResult) -> bool:
    """Determine if the content should be censored based on the safety result.

    Args:
        safety_result (SafetyResult): The result of the safety check.

    Returns:
        bool: True if the content should be censored, False otherwise.
    """
    if safety_result.is_csam:
        return True

    if safety_result.is_nsfw and self.should_censor_nsfw:
        return True

    if safety_result.is_hate_speech and self.should_censor_hate_speech:
        return True

    if safety_result.is_violent and self.should_censor_violent:
        return True

    return bool(safety_result.is_self_harm and self.should_censor_self_harm)

__init__

__init__(
    should_censor_nsfw: bool = True,
    should_censor_hate_speech: bool = True,
    should_censor_violent: bool = True,
    should_censor_self_harm: bool = True,
) -> None

Initialize the SafetyRules with optional parameters to set censorship preferences.

Args: should_censor_nsfw (bool): Whether to censor NSFW content. Defaults to True. should_censor_hate_speech (bool): Whether to censor hate speech content. Defaults to True. should_censor_violent (bool): Whether to censor violent content. Defaults to True. should_censor_self_harm (bool): Whether to censor self-harm content. Defaults to True.

Source code in horde_sdk/safety.py
def __init__(
    self,
    should_censor_nsfw: bool = True,
    should_censor_hate_speech: bool = True,
    should_censor_violent: bool = True,
    should_censor_self_harm: bool = True,
) -> None:
    """Initialize the SafetyRules with optional parameters to set censorship preferences.

    Args:
    should_censor_nsfw (bool): Whether to censor NSFW content. Defaults to True.
    should_censor_hate_speech (bool): Whether to censor hate speech content. Defaults to True.
    should_censor_violent (bool): Whether to censor violent content. Defaults to True.
    should_censor_self_harm (bool): Whether to censor self-harm content. Defaults to True.
    """
    self.should_censor_nsfw = should_censor_nsfw
    self.should_censor_hate_speech = should_censor_hate_speech
    self.should_censor_violent = should_censor_violent
    self.should_censor_self_harm = should_censor_self_harm