Skip to content

fix: azure content safety plugin with blocklist#1061

Merged
VisargD merged 2 commits into
Portkey-AI:mainfrom
b4s36t4:fix/azure-plugin-blocklist
Apr 25, 2025
Merged

fix: azure content safety plugin with blocklist#1061
VisargD merged 2 commits into
Portkey-AI:mainfrom
b4s36t4:fix/azure-plugin-blocklist

Conversation

@b4s36t4

@b4s36t4 b4s36t4 commented Apr 24, 2025

Copy link
Copy Markdown
Contributor

Code Quality type: bug fix

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)

How Has This Been Tested?

  • Unit Tests
  • Integration Tests
  • Manual Testing

Screenshots (if applicable)

N/A

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Related Issues

N/A

Quality Recommendations

  1. Add unit tests to verify the behavior of the simplified blocklist check logic

  2. Add error handling for cases where the response structure might be different than expected

  3. 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)
Loading

@VisargD
VisargD merged commit 6021da6 into Portkey-AI:main Apr 25, 2025
@b4s36t4
b4s36t4 deleted the fix/azure-plugin-blocklist branch April 25, 2025 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants