Class ModerationResult
java.lang.Object
com.tnsai.quality.security.moderation.ModerationResult
Result of content moderation check.
Contains moderation status, category flags, and confidence scores.
Moderation Categories
| Category | Description |
|---|---|
| HATE | Hate speech and discrimination |
| HARASSMENT | Personal attacks, bullying |
| VIOLENCE | Violent content or threats |
| SELF_HARM | Self-harm related content |
| SEXUAL | Explicit sexual content |
| ILLEGAL | Illegal activities |
| TOXIC | Generally toxic content |
| SPAM | Spam or promotional content |
Actions
- ALLOW: Content is safe, proceed normally
- WARN: Content is suspicious, log and proceed with caution
- BLOCK: Content violates policies, reject request
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumAction to take based on moderation.static classBuilder for ModerationResult.static enumContent categories for moderation. -
Method Summary
Modifier and TypeMethodDescriptionstatic ModerationResultallowed()Returns an allowed result.static ModerationResultblock(String reason, Map<ModerationResult.Category, Double> categoryScores, List<String> flaggedContent) Returns a blocked result.static ModerationResult.Builderbuilder()Creates a builder for complex results.Gets the recommended action.Gets the category confidence scores.Gets a detailed safe response.Gets all flagged categories.Gets the flagged content snippets.Gets the reason for the action.Gets a safe response to return when blocked.doublegetScore(ModerationResult.Category category) Gets the score for a specific category.booleanChecks if content has warnings.booleanChecks if content is allowed.booleanChecks if content is blocked.booleanisFlagged(ModerationResult.Category category) Checks if a category was flagged.toString()static ModerationResultwarn(String reason, Map<ModerationResult.Category, Double> categoryScores) Returns a warning result.
-
Method Details
-
allowed
Returns an allowed result.- Returns:
- allowed result
-
warn
public static ModerationResult warn(String reason, Map<ModerationResult.Category, Double> categoryScores) Returns a warning result.- Parameters:
reason- reason for warningcategoryScores- category confidence scores- Returns:
- warning result
-
block
public static ModerationResult block(String reason, Map<ModerationResult.Category, Double> categoryScores, List<String> flaggedContent) Returns a blocked result.- Parameters:
reason- reason for blockingcategoryScores- category confidence scoresflaggedContent- specific content that was flagged- Returns:
- blocked result
-
builder
Creates a builder for complex results.- Returns:
- new builder
-
getAction
Gets the recommended action.- Returns:
- action to take
-
isAllowed
public boolean isAllowed()Checks if content is allowed.- Returns:
- true if allowed
-
isBlocked
public boolean isBlocked()Checks if content is blocked.- Returns:
- true if blocked
-
hasWarning
public boolean hasWarning()Checks if content has warnings.- Returns:
- true if warned
-
getCategoryScores
Gets the category confidence scores.- Returns:
- map of category to score
-
getScore
Gets the score for a specific category.- Parameters:
category- category to check- Returns:
- score (0.0 - 1.0) or 0.0 if not flagged
-
isFlagged
Checks if a category was flagged.- Parameters:
category- category to check- Returns:
- true if flagged
-
getFlaggedCategories
Gets all flagged categories.- Returns:
- set of flagged categories
-
getReason
Gets the reason for the action.- Returns:
- reason or null if allowed
-
getFlaggedContent
Gets the flagged content snippets.- Returns:
- list of flagged content
-
getSafeResponse
Gets a safe response to return when blocked.- Returns:
- safe response message
-
getDetailedSafeResponse
Gets a detailed safe response.- Returns:
- detailed safe response
-
toString
-