Azure AI Content Safety – Text Moderation on multiple string properties using a Blocklist in Optimizely CMS

In this article, I demonstrate how the text moderation feature from Azure AI Content Safety service can be used to filter text on multiple string properties, using a blocklist to identify harmful or unwanted content. This is done as part of the content publishing process within Optimizely CMS.

This article discusses using the concept of Azure AI Content Safety to moderate multiple string properties, as opposed to just one as mentioned in the linked example. You can find the original article here.

Text Moderation on multiple string properties using a blocklist can be done by downloading the “Patel.AzureAIContentSafety.Optimizely” NuGet package. You can get this package from the Optimizely NuGet Feed or the NuGet Feed.

After the NuGet Package has been downloaded and the initial Configuration/Setup steps have been completed, it is necessary to add a boolean property with the [TextAnalysisBlocklistAllowed] attribute to the Start Page type in Optimizely. This action is essential to activate this functionality. More details about this can be found here.

After you download the NuGet Package and finish the initial setup, you need to add a boolean property with the [TextAnalysisBlocklistAllowed] attribute to the Start Page type in Optimizely. This is important to activate this feature. You can find more details about this here.

The next step is to add a string property to a Optimizely CMS Content type that inherits from IContent. This string property requires the addition of a [TextAnalysisBlocklistDropdown] attribute. More details about this can be found here.

The final step is to add multiple string properties with the [TextAnalysisBlocklist] attribute. More information can be found in this link. These string properties should be added to the same content type where the string property with the TextAnalysisBlocklistDropdown attribute was added.

When the above steps are complete, a blocklist can be chosen from the dropdown. The screenshot below shows an example of this being done.

The items linked to the blocklist are shown below in the screenshot. You can find this information in the Blocklist Management Add-On, which is part of the NuGet Package “Patel.AzureAIContentSafety.Optimizely”. For more details, you can visit this link.

When the steps above are complete, the content will be ready for publishing and text moderation, using the selected blocklist.

Response from the API via the Console
Azure AI Content Safety – Analysis of Text using a Blocklist operation complete
Blocklist Match Count: 1
Azure AI Content Safety – Analysis of Text using a Blocklist operation complete
Blocklist Match Count: 1

Once the text moderation is done, if any published text matches any items in the chosen blocklist, an error message will appear in the CMS. This will prevent the user from publishing the content as shown in the screenshot below.

If the text being published doesn’t match any blocked items linked to the selected blocklist, then the content will be published and available in the CMS.