feat(ai-aws-content-moderation): add request_check_roles and request_check_mode - #13773
Open
shreemaan-abhishek wants to merge 1 commit into
Open
feat(ai-aws-content-moderation): add request_check_roles and request_check_mode#13773shreemaan-abhishek wants to merge 1 commit into
shreemaan-abhishek wants to merge 1 commit into
Conversation
…check_mode Bring the request-side selectivity of ai-aliyun-content-moderation to the AWS plugin: `request_check_roles` picks which message roles are moderated (user/tool/system) and `request_check_mode` limits user/tool moderation to the newest turn instead of re-scoring the whole conversation on every request. system is always moderated when enabled, since it can be poisoned by malicious ToolCall arguments. Defaults keep today's coverage: all roles, every message. A protocol that cannot extract a configured role now goes through fail_mode instead of silently passing the content unmoderated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
ai-aws-content-moderationmoderates the request side by callingextract_request_content, which takes every message of every role and scores the whole conversation on every turn.ai-aliyun-content-moderationhas had role and turn selectivity since #13646; this brings the same options to the AWS plugin.request_check_roles(array, default["user","tool","system"]) selects which message roles are moderated.user/toolfollowrequest_check_mode;systemis moderated on every request because it can be poisoned by malicious ToolCall arguments overwriting the system prompt.request_check_mode(last/all, defaultall) limitsuser/toolmoderation to the latest consecutive block of selected-role messages, so history is not re-scored (and re-billed to Comprehend) each turn.All selected roles' text is collected and scored in a single Comprehend call:
DetectToxicContenttakes a flat list of text segments with no role field, so per-role calls would only cost extra requests.No new extraction code is needed —
extract_turn_content(body, mode, roles)andextract_system_content(body)already exist on every protocol adapter from #13646.Defaults preserve current coverage rather than mirroring the aliyun plugin's
["user"]+last: this plugin moderates everything today, and a narrower default would silently moderate less after an upgrade. Selectivity is opt-in. Assistant content is the one thing that drops out, since no extractor collects it (it is the LLM's own prior output, echoed back by the client).One behavior change beyond the new options: when the active protocol cannot extract a configured role (
passthroughimplements neither extractor), the request goes throughbinding.on_unsupportedsofail_modedecides, instead of silently passing the content unmoderated. With the defaultfail_mode: skipnothing changes.Checklist
t/plugin/ai-aws-content-moderation.tTEST 36-49: default role/mode coverage,lastvsall, role selection, schema validation, and the unsupported-protocolfail_modepath)docs/en/latest/plugins/ai-aws-content-moderation.mdand the zh translation)prove -I. t/plugin/ai-aws-content-moderation.t— all 49 tests pass;make lintclean