Skip to content

Moderation redact leaves toxicity in output #2000

Open

Description

@feiiiiii5

Description

Moderation(action="redact") only replaces profanity. Toxicity matches are classified (classification="toxicity", score 0.95) but left in the text, and transformed_text stays None. The pipeline then forwards the original toxic string unchanged. The sibling PII guard defines redact as replacing matches with [REDACTED:label], and the pipeline chains transformed_text from REDACT results.

Reproduction

from openlit.guard.moderation import Moderation
result = Moderation(action="redact").evaluate("kill yourself")
# action=REDACT, classification="toxicity", transformed_text=None
# -> toxic phrase is still forwarded downstream

Expected

Redaction applies to toxicity patterns as well, producing a populated transformed_text with no toxic phrase.

Proposed fix

Compile the existing toxicity patterns once and substitute [REDACTED:toxicity] into the text alongside profanity; keep classification/score and other actions unchanged.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions