Moderations API

Classify text and images for policy violations, returning per-category flags and confidence scores. Moderation is free. OpenAI only.

Parsed Objects

UniLM.ModerationResultType
ModerationResult

One classification result: flagged (any policy violation), categories (per-category booleans), and category_scores (per-category confidence); raw holds the unparsed JSON result.

source

Result Types

Functions

UniLM.moderateFunction
moderate(input; model="omni-moderation-latest", service=OPENAIServiceEndpoint)

Classify input (a String, or a vector of content parts) for policy violations (free). Returns ModerationSuccess, ModerationFailure, or ModerationCallError.

Pass config::Union{Nothing,RequestConfig} to override the timeout budget for this call (a single bounded attempt; max_attempts does not apply).

source
UniLM.is_flaggedFunction
is_flagged(r) -> Bool

True if any moderation result is flagged. Works on ModerationResult/ModerationResponse/ModerationSuccess.

A call that did not succeed has no verdict, so ModerationFailure and ModerationCallError throw an ArgumentError rather than answering false: in the usual is_flagged(moderate(text)) && reject() shape, a false from a failed call would wave unmoderated content straight through. Check issuccess first, or handle the throw, and decide explicitly what an unavailable verdict should mean.

source

Usage

# Classify text for policy violations (free)
result = moderate("...text to check...")
result isa ModerationSuccess && println("Flagged? ", is_flagged(result))

# Inspect per-category flags and scores
if result isa ModerationSuccess
    for m in result.response.results
        m.flagged && println(m.categories)
    end
end