ai-aliyun-content-moderation
Moderates request content with Alibaba Cloud before the LLM.
ai-aliyun-content-moderationPriority 1029What it does
ai-aliyun-content-moderation asks Alibaba Cloud content moderation to rate each prompt before the model receives it, and with Check response on, the model's answer too. A prompt rated at or above Risk level bar is refused with Deny code, and one rated below goes on to the model.
It rates only what an AI proxy on the same route handles, ai-proxy or ai-proxy-multi. In the example, a prompt the service rates high is answered 403 with the answer the service advises, and a prompt rated none reaches the model, whose answer the client gets.
When to use it
- A chat assistant for customers in China, whose prompts are rated by Alibaba Cloud in the
cn-shanghairegion before any model sees them. - A team that already moderates what its users post with Alibaba Cloud and wants the same verdict on prompts sent to a model.
- Routes that spread prompts over several models with ai-proxy-multi, rated the same way as on a route with one model.
- A product for a young audience, where a lower Risk level bar refuses prompts the default bar lets through.
Not for refusing prompts by patterns you write yourself — see ai-prompt-guard (Allows or denies prompts that match configured patterns), toxicity scores per category from Amazon Comprehend — see ai-aws-content-moderation (Moderates request content with AWS Comprehend before the LLM) or asking your own authorization service whether a request may go on — see forward-auth (Delegates authentication to an external service).
Set it up
Refuse prompts Alibaba Cloud content moderation rates high risk or above
Acts only on a route that also carries ai-proxy or ai-proxy-multi.
Under Basics set Endpoint to https://green-cip.cn-shanghai.aliyuncs.com, set Region ID to cn-shanghai, set Access key ID to $env://ALIBABA_CLOUD_ACCESS_KEY_ID and set Access key secret to <secret>. Under Behavior leave Risk level bar at high and set Deny code to 403.
{
"endpoint": "https://green-cip.cn-shanghai.aliyuncs.com",
"region_id": "cn-shanghai",
"access_key_id": "$env://ALIBABA_CLOUD_ACCESS_KEY_ID",
"access_key_secret": "<secret>",
"risk_level_bar": "high",
"deny_code": 403
}
Things to know
- Risk level bar — With the bar at
high, a prompt the service rateshighis refused, and one it ratesnonereaches the model and gets its answer. - Deny message — Left empty, the refused client reads the answer the moderation service advises for that prompt, in the body of the
403in the example. - The same configuration refuses the same prompt on a route whose model is chosen by ai-proxy-multi instead of ai-proxy.
- Endpoint — A moderation call that fails is only logged: the content travels on to the model unchecked.
- Endpoint — An address without its scheme is refused when you save.
- Check response — On a streamed answer the default final_packet mode only tags flagged text and sends it on, while realtime cuts the stream.
- Risk level bar — A risk at or above the bar is denied, so a bar of none denies every request the service scores.
- Fail mode — Nothing is scanned unless an AI proxy on the same route picked a model first, and the default then lets the request through in silence.
- Request check roles — Only
system,toolandusercan be listed;assistantis refused when you save. - Keepalive — Off, every request this plugin checks answers 500: the connection to the moderation service is refused its pool setting before anything is sent.
- AdviceSet Deny code to a 4xx, for example
403, when your clients should treat a refused prompt as an error.
Settings
The fields as the console shows them, section by section.
Basics
endpointstringRequiredThe moderation service address for your region, such as https://green-cip.cn-shanghai.aliyuncs.com.
pattern
^https?://region_idstringRequiredaccess_key_idstringRequiredaccess_key_secretstringRequiredStored on the engine and shown only to roles that manage this object.
check_requestbooleandefault truecheck_responsebooleandefault falseBehavior
risk_level_barstringdefault highdeny_codeintegerdefault 200The status a denied request is answered with, where 200 reads as a normal completion to client libraries and a 4xx as an error.
deny_messagestringfail_modestringdefault skipWhat to do with a request the plugin cannot inspect: skip lets it through, warn also logs it, and error rejects it with 500. Plain traffic that did not pass through an AI proxy is such a request.
request_check_modestringdefault lastWhich messages of the selected roles to moderate: last is the latest consecutive block, and all is every one of them. A system role selected below is checked on every request, whatever the mode.
request_check_rolesarray of stringsdefault ["user"]The message roles moderated on the request side. User and tool follow the mode above. A selected system role is checked on every request, and a tool result is read only where the protocol gives it a role of its own.
request_check_servicestringdefault llm_query_moderationresponse_check_servicestringdefault llm_response_moderationrequest_check_length_limitintegerdefault 2000response_check_length_limitintegerdefault 5000timeoutintegerdefault 10000How long the moderation service has to answer one call.
ssl_verifybooleandefault trueAdvanced
stream_check_modestringdefault final_packetRealtime checks a streamed answer in batches as it arrives, and final packet checks it once at the end and tags the last chunk.
stream_check_intervalnumberdefault 3How long a batch of streamed text may gather before it is checked, in realtime mode.
stream_check_cache_sizeintegerdefault 128How much streamed text a batch may gather before it is checked, in realtime mode.
keepalivebooleandefault truekeepalive_poolintegerdefault 30keepalive_timeoutintegerdefault 60000