[Tracker]
Update Summary: [One-line status update for stakeholders]
Check-in Date: MM/DD/YYYY
Blocked by: [#XXXXXX] (New issues on new lines)
Additional Collaborators: @username1, @username2
Metadata is used by the AI Tracker. Docs and additional fields here.
[/Tracker]

Problem/Motivation

The help text for "Enable OpenAI Moderation" on /admin/config/ai/providers/anthropic is incorrect. There is no "AI External Moderation" module to enable - but configuration does need to be completed on /admin/config/ai/ai-external-moderation

Also - I'm not sure if it is possible to do _anything_ that enables the checkbox.

Proposed resolution

Target date or deadline

Remaining tasks

AI usage (if applicable)

[ ] AI Assisted Issue
This issue was generated with AI assistance, but was reviewed and refined by the creator.

[ ] AI Assisted Code
This code was mainly generated by a human, with AI autocompleting or parts AI generated, but under full human supervision.

[ ] AI Generated Code
This code was mainly generated by an AI with human guidance, and reviewed, tested, and refined by a human.

[ ] Vibe Coded
This code was generated by an AI and has only been functionally tested.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

ultimike created an issue. See original summary.

dan2k3k4’s picture

Project: amazee.ai Private AI Provider » Anthropic Provider
kelly.m.jacobs’s picture

Assigned: Unassigned » kelly.m.jacobs
kelly.m.jacobs’s picture

[ X] AI Generated Code
This code was mainly generated by an AI with human guidance, and reviewed, tested, and refined by a human.

I've made some adjustments with the removal of the AI External Moderation module.

  • Change the help text
  • Rather than checking for the module to display additional help text, check for external moderation config
  • Also make changes to the submitForm function
kelly.m.jacobs’s picture

Assigned: kelly.m.jacobs » Unassigned
Status: Active » Needs review
arianraeesi’s picture

erichomanchuk’s picture

Assigned: Unassigned » erichomanchuk
erichomanchuk’s picture

Assigned: erichomanchuk » Unassigned
StatusFileSize
new26.76 KB
new22.85 KB
new10.15 KB
new83.82 KB
new20.62 KB

Here's what I found so far:

1. I can confirm that this change fixes the problem that as of ai 1.2.x branch the ai_external_moderation submodule is just a placeholder module to allow for uninstalling and the code has been incorporated into the ai module. So this does fix the problem of fixing the help text. (https://www.drupal.org/project/ai/issues/3479913)

OpenAI module not installed
No openai installed

OpenAI module installed and configured
Openai Configured

OpenAI enabled for moderation
OpenAI enabled

2. I get a schema error when I save the form. This is because the config value is missing from the schema file "ai_provider_anthropic/config/schema/ai_provider_anthropic.schema.yml" and also should be added to the install file "ai_provider_anthropic/config/install/ai_provider_anthropic.settings.yml".

I also wonder if it needs to be saved or we can revert saving it as a config setting since it is just used as a user agreement / consent that the user understands that without moderation they could be banned.

'#default_value' => $disabled ? 1 : $config->get('moderation_checkbox'),

change back to

'#default_value' => $disabled ? 1 : 0,

Schema errors for ai_provider_anthropic.settings with the following errors: ai_provider_anthropic.settings:moderation_checkbox missing schema. These errors mean there is configuration that does not comply with its schema. This is not a fatal error, but it is recommended to fix these issues. For more information on configuration schemas, check out <a href="https://www.drupal.org/docs/drupal-apis/configuration-api/configuration-schemametadata">the documentation</a>.

3. When first configuring the Anthropic Provider the checkbox "No Moderation Needed" is set to checked. Should this not be unchecked? Shouldn't we be forcing the user to confirm that they understand the risks of using the API with no moderation.

'#default_value' => $disabled ? 1 : $config->get('moderation_checkbox'),

Shouldn't this be

'#default_value' => $disabled ? 0 : $config->get('moderation_checkbox'),

Anthropic provider form when first configuring
Default form

4. Then if we start with the "No Moderation Needed" Checkbox started unchecked do we need the javascript that is triggered when you check the box? The javascript basically disables the save button and changes it's text to state that you should read the checkbox and disables saving the form for 10secs.

JS used to disable save config when checkbox is transitioned from unchecked to checked.
JS Disabled

I also noticed that the JS file here "ai_provider_anthropic/js/verification.js" works on claro but it breaks on the gin theme which is installed with Drupal CMS as the id it is targeting #edit-submit is different on the GIN theme and it causes a glitch where you can't press the "Save Configuration" button for 10 seconds but there is no indication.

I can open a different ticket for this issue as it is unrelated but I feel like if we just always force users on saving the Anthropic Provider form to have to check "No Moderation Needed" then there shouldn't be a need for this JS functionality.

a.dmitriiev’s picture

Status: Needs review » Needs work

There was a branch, but no MR. I have opened MR and added a comment. Maybe there is a way to avoid coupling moderation with OpenAI only?

erichomanchuk’s picture

Assigned: Unassigned » erichomanchuk

I'll update the text so it doesn't seem like only openAI can be used for text moderation as other providers offer moderation as well.

erichomanchuk’s picture

Assigned: erichomanchuk » Unassigned
Status: Needs work » Needs review
StatusFileSize
new212.34 KB
new199.51 KB
new197.12 KB
new251.73 KB

I've made the following changes to remove the OpenAI recommendation for moderation so that it is more agnostic as to what provider can be used for moderation.

1. Removed the checkbox "Enable OpenAI Moderation". Just providing a status message now to indicate that external moderation should be setup but it doesn't necessarily need to be OpenAI as the moderator. This then leads to not having openai default moderator installed for a user and they need to configure it from the external moderation config form. This I feel is better anyways and moves the onus back to the site builder to configure. I also want to note that the moderation model the anthropic provider was setting for openai "openai__text-moderation-latest" is now deprecated and doesn't work for moderation anymore so this helps not having to maintain this coding logic anymore.

Default Config Form - Pre-moderation configuration
Default config form

2. I have added an uninstall hook to remove the config "openai_moderation" config variable no longer needed

3. Currently users still get the JS 10 second delay and submit button text update when proceeding with no moderation. I think this is redundant now that the config form starts with "No Moderation Needed" off (unchecked) by default as opposed to checked by default before and this JS never got run.

NOTE: I think the JS should be removed and would like anyone else's thoughts on this. As mentioned this JS does not function correctly in the GIN theme as the id for the submit is different so if we want to keep it will need to move to data attributes on the submit.

No Moderation Needed Interaction
No moderation needed

4. When moderation is already configured then the message is updated and the "No moderation Needed" checkbox is disabled

No moderation disabled when moderation configured
No moderation disabled

5. Made the API key required to save the form as it was only optional before.

6. Added validation for the API key to check that configured models return and provide user feedback that there is an issue with the key. I noticed that when I called $models = $provider->getConfiguredModels(); on validating that a previous cache of modules could be returned if switching keys so I added cache deletion and validation to check that the models were not empty which can be returned if a previous key was used.

Validate API Key
Bad key validation

7. I also updated some of the wording for the inputs and messages.

ajv009’s picture

Assigned: Unassigned » ajv009

I thought we were not adding features 1.2 anymore, right?
I have a few tiny changes which I will add to this, but I think this should be bumped to v2 or 1.4 I think?

ajv009’s picture

Assigned: ajv009 » Unassigned

Hey @erichomanchuk, nice work on this. I tested the MR on a fresh Drupal 11.3.5 install with ai 1.3.1 and ai_provider_anthropic 1.2.2. The provider-agnostic moderation approach is a solid improvement over the old OpenAI-specific logic.

Everything from #12 works well. I can confirm:

  • Warning message shows correctly when no moderation is configured
  • Status message shows when moderation IS configured, checkbox gets disabled
  • API key validation catches bad keys and returns a clear error
  • Update hook 10005 cleans up the old openai_moderation config value
  • No schema errors after the update

I pushed a follow-up commit with a few fixes I found during testing:

  • Fixed null pointer in validateForm: getKey() can return NULL if the key entity gets deleted between page load and submit, which would crash on ->getKeyValue(). Added a null check.
  • Replaced hardcoded URLs with Url::fromRoute(): the /admin/config/ai/ai-external-moderation paths now use Url::fromRoute('ai.external_moderation_settings') for proper Drupal routing.
  • Removed verification.js and library: agree with your suggestion in #8 that the 10-second submit delay is redundant now that the checkbox starts unchecked. It was also broken on GIN theme as you noted (targets #edit-submit which doesn't exist there). Removing it makes the form much smoother to use.
  • Hardened moderations config read: added is_array() check to prevent a foreach crash if the config value is not an array (the ?? [] only catches NULL, not other non-array types).

Transparency note: This research and comment were drafted with highly supervised usage of Claude Code. Not here to waste anyone's efforts or demean the work being done, and definitely not posting AI slop. I verified everything personally. If I'm not doing something right process-wise, please flag it, would be more than happy to course correct.

a.dmitriiev’s picture

Status: Needs review » Reviewed & tested by the community

I have reviewed the MR again with the additional changes added by @ajv009. It is now not relying only on OpenAI anymore and the form settings experience is indeed better. Moving to RTBC.

a.dmitriiev’s picture

Status: Reviewed & tested by the community » Fixed

Added to merge train.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • a.dmitriiev committed b98236a3 on 1.2.x
    #3578821: Make necessary fixes after removal of AI External Moderation...
arianraeesi’s picture

Issue tags: -AI Product Development

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.