ProfanityFilter

org.llm4s.agent.guardrails.builtin.ProfanityFilter
See theProfanityFilter companion object
class ProfanityFilter(customBadWords: Set[String], caseSensitive: Boolean) extends InputGuardrail, OutputGuardrail

Filters profanity and inappropriate content.

This is a basic implementation using a word list. For production, consider integrating with external APIs like:

  • OpenAI Moderation API
  • Google Perspective API
  • Custom ML models

Can be used for both input and output validation.

Value parameters

caseSensitive

Whether matching should be case-sensitive

customBadWords

Additional words to filter beyond the default list

Attributes

Companion
object
Graph
Supertypes
trait Guardrail[String]
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

override def transform(input: String): String

Optional: Transform the output after validation. Default is identity (no transformation).

Optional: Transform the output after validation. Default is identity (no transformation).

Value parameters

output

The validated output

Attributes

Returns

The transformed output

Definition Classes
def validate(value: String): Result[String]

Validate a value.

Validate a value.

This is a PURE FUNCTION - no side effects allowed. Same input always produces same output.

Value parameters

value

The value to validate

Attributes

Returns

Right(value) if valid, Left(error) if invalid

Inherited methods

def andThen(other: Guardrail[String]): Guardrail[String]

Compose this guardrail with another sequentially.

Compose this guardrail with another sequentially.

The second guardrail runs only if this one passes.

Value parameters

other

The guardrail to run after this one

Attributes

Returns

A composite guardrail that runs both in sequence

Inherited from:
Guardrail

Concrete fields

override val description: Option[String]

Optional description of what this guardrail validates.

Optional description of what this guardrail validates.

Attributes

val name: String

Name of this guardrail for logging and error messages.

Name of this guardrail for logging and error messages.

Attributes