Repository navigation
fix: keep AI moderation from deleting posts with trusted links - #66
Merged
Merged
Conversation
Alam-2U
approved these changes
Oct 15, 2026
The classifier only sees a post's text, not the course it was posted in, so it could not tell a learner sharing a CodePen in a CSS course from link spam, and course discussions were losing legitimate posts (LP-1310). Links to trusted domains are now removed before content is classified. The rest of the post is still classified, so adding a trusted link to spam does not get it through, and links to any other domain are left for the classifier to judge. Content left with nothing to classify is not sent to the classifier at all. The domains come from the AI_MODERATION_TRUSTED_LINK_DOMAINS setting, which each deployment configures. Forum trusts no domain by default.
This was referenced Oct 15, 2026
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 moderation was deleting legitimate posts that contain links. W3C reported that, in
course-v1:W3Cx+CSS.0x+2T2025, posts with CodePen links are routinely soft-deleted by the forum bot, even though learners and the course team share CodePens as a normal part of the course.The classifier only ever sees the text of a post, never the course it was posted in, so it cannot tell a learner sharing their CodePen in a CSS course from someone dropping a link to advertise. The production prompt also lists "external links (especially non-educational domains)" as a spam signal and only names
.edulinks as legitimate.This PR removes links to trusted domains from a post before it is classified, without changing the prompt:
AI_MODERATION_TRUSTED_LINK_DOMAINSsetting, which each deployment configures. Forum trusts no domain by default. For edx.org the list is set in edx-internal.codepen.ioandwww.codepen.iomatch, whilecodepen.io.evil.exampleandnotcodepen.iodo not.<a href>to a trusted domain is replaced by its link text. An anchor whose href is untrusted is kept, even when its text is a trusted URL.<p>/<br>tags is left, the classifier is not called and the post is not flagged. A post with an<img src>is still classified.JIRA: https://2u-internal.atlassian.net/browse/LP-1310
Changes
forum/ai_moderation/links.py(new):strip_trusted_links()andis_blank().forum/ai_moderation/service.py: strips trusted links right after the waffle-flag check, before the cache lookup and the classifier call.forum/settings/common.py: declaresAI_MODERATION_TRUSTED_LINK_DOMAINS, defaulting to[].docs/how-tos/configure_ai_moderation.rst: documents the new setting.0.7.3.Things to note
codepen.ioandzoom.usfor the edxapp LMS and CMS on prod, stage and edge. Subdomains such asus02web.zoom.usare included. More domains can be added with a config change.release-ulmocommit before #15007 is merged. Without the config, the new code trusts nothing and behaves as before.Testing
tests/test_ai_moderation_links.pyand aTestAIModerationTrustedLinksclass intests/test_ai_moderation.py, including that nothing is trusted unless configured.edxapp-lms/prod-config.yamland passed it throughplugin_settings. I then created threads, responses and replies, with a fake classifier that calls any post mentioning CodePen spam.Manual testing instructions
AI_MODERATION_BACKEND,AI_MODERATION_API_URL,AI_MODERATION_CLIENT_ID,AI_MODERATION_USER_ID, andAI_MODERATION_TRUSTED_LINK_DOMAINS = ["codepen.io", "zoom.us"].discussions.enable_ai_moderationanddiscussions.enable_ai_auto_delete_spamfor a test course with a waffle flag course override.My solution: https://codepen.io/<user>/pen/<id>, why is the footer not sticky?. It should stay visible and not be flagged.Guaranteed A grades! WhatsApp +1-555-0199 https://codepen.io/<user>/pen/<id>. It should be flagged and soft-deleted, with an entry inModerationAuditLog.Merge checklist:
Check off if complete or not applicable: