Moderations API
Classify text and images for policy violations, returning per-category flags and confidence scores. Moderation is free. OpenAI only.
Parsed Objects
UniLM.ModerationResult — Type
ModerationResultOne classification result: flagged (any policy violation), categories (per-category booleans), and category_scores (per-category confidence); raw holds the unparsed JSON result.
UniLM.ModerationResponse — Type
ModerationResponseA moderation response: results, one ModerationResult per input, and the model used; raw holds the unparsed JSON response.
Result Types
UniLM.ModerationSuccess — Type
Successful moderate result wrapping a ModerationResponse.
UniLM.ModerationFailure — Type
Moderations API error result: HTTP status and the raw response body.
UniLM.ModerationCallError — Type
Local/transport error from a Moderations API call (the request never completed).
Functions
UniLM.moderate — Function
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).
UniLM.is_flagged — Function
is_flagged(r) -> BoolTrue 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.
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