fix: azure content safety plugin with blocklist#1061
Merged
Conversation
VisargD
approved these changes
Apr 25, 2025
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.
Author Description
Description
🔄 What Changed
Fixed the Azure Content Safety plugin's blocklist checking logic by simplifying how it detects blocklist hits.
🔍 Impact of the Change
Improves code readability and slightly enhances performance by eliminating unnecessary iteration through the blocklist matches.
📁 Total Files Changed
1 file modified: plugins/azure/contentSafety.ts (1 addition, 3 deletions)
🧪 Test Added
N/A - No tests were added with this PR.
🔒 Security Vulnerabilities
N/A - No security vulnerabilities were addressed in this change.
Motivation
The previous implementation was unnecessarily complex, checking each blocklist match item individually when simply checking if the array has any items would achieve the same result.
Type of Change
How Has This Been Tested?
Screenshots (if applicable)
N/A
Checklist
Related Issues
N/A
Quality Recommendations
Add unit tests to verify the behavior of the simplified blocklist check logic
Add error handling for cases where the response structure might be different than expected
Consider adding a comment explaining why checking the array length is sufficient
Sequence Diagram
sequenceDiagram participant Client participant AzureContentSafetyPlugin as Azure Content Safety Plugin participant AzureAPI as Azure Content Safety API Client->>AzureContentSafetyPlugin: Request with content to check AzureContentSafetyPlugin->>AzureAPI: Send content for safety analysis AzureAPI-->>AzureContentSafetyPlugin: Return response with blocklistsMatch array Note over AzureContentSafetyPlugin: Old Implementation: Note over AzureContentSafetyPlugin: Check if any blocklist items were hit by Note over AzureContentSafetyPlugin: iterating through blocklistsMatch array Note over AzureContentSafetyPlugin: and checking if any match.matchResults.length > 0 Note over AzureContentSafetyPlugin: New Implementation: Note over AzureContentSafetyPlugin: Simply check if blocklistsMatch array length > 0 AzureContentSafetyPlugin->>Client: Return verdict (true/false)