Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import { handler as promptSecurityProtectResponse } from './promptsecurity/prote
import { handler as panwPrismaAirsintercept } from './panw-prisma-airs/intercept';
import { handler as defaultjwt } from './default/jwt';
import { handler as defaultrequiredMetadataKeys } from './default/requiredMetadataKeys';
import { handler as walledaiguardrails } from './walledai/guardrails';
import { handler as walledaiguardrails } from './walledai/walledprotect';
import { handler as defaultregexReplace } from './default/regexReplace';

export const plugins = {
Expand Down Expand Up @@ -138,6 +138,6 @@ export const plugins = {
intercept: panwPrismaAirsintercept,
},
walledai: {
guardrails: walledaiguardrails,
walledprotect: walledaiguardrails,
},
};
};
50 changes: 9 additions & 41 deletions plugins/walledai/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"functions": [
{
"name": "Walled AI Guardrail for checking safety of LLM inputs",
"id": "guardrails",
"id": "walledprotect",
"supportedHooks": ["beforeRequestHook", "afterRequestHook"],
"type": "guardrail",
"description": [
Expand All @@ -28,51 +28,26 @@
"parameters": {
"type": "object",
"properties": {
"text_type": {
"type": "string",
"label": "Text Type",
"description": [
{
"type": "subHeading",
"text": "Type of Text , defaults to 'prompt'"
}
],
"default": "prompt"
},
"generic_safety_check": {
"type": "string",
"label": "Generic Safety Check",
"description": [
{
"type": "subHeading",
"text": "Boolean value to enable generic safety checks on the text input. Defaults to 'true'."
}
],
"description": "Boolean value to enable generic safety checks on the text input. Defaults to 'true'.",
"default": true
},
"greetings_list": {
"type": "array",
"label": "Greetings List",
"description": [
{
"type": "subHeading",
"text": "List of greetings to be used in the guardrail check. This can help in identifying and handling greetings appropriately."
}
],
"description": "List of greetings to be used in the guardrail check.",
"items": {
"type": "string"
"type": "string",
"enum": ["Casual & Friendly", "Professional & Polite"]
},
"default": ["Casual & Friendly", "Professional & Polite"]
"default": ["Casual & Friendly"]
},
"pii_list": {
"type": "array",
"label": "PII LIST",
"description": [
{
"type": "subHeading",
"text": "Identify all the PII for only the following types of PII will be checked in the text input. Defaults to empty list"
}
],
"description": "PII types that should be checked in the input text.",
"items": {
"type": "string",
"enum": [
Expand All @@ -98,15 +73,8 @@
"compliance_list": {
"type": "array",
"label": "List of Compliance Checks",
"description": [
{
"type": "subHeading",
"text": "List of compliance checks to be performed on the text input. This can help in ensuring that the text adheres to specific compliance standards. Defaults to empty"
}
],
"items": {
"type": "string"
},
"description": "Compliance checks to be performed on the text input.",
"items": { "type": "string" },
"default": []
}
}
Expand Down
32 changes: 31 additions & 1 deletion plugins/walledai/walledai.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { handler } from './guardrails';
import { handler } from './walledprotect';
import testCredsFile from './creds.json';
import { HookEventType, PluginContext, PluginParameters } from '../types';

Expand Down Expand Up @@ -99,4 +99,34 @@ describe('WalledAI Guardrail Plugin Handler (integration)', () => {
expect(result.data).toBeDefined();
// Optionally, check if compliance_list was respected in the response if API supports it
});

it('should handle conversational text format', async () => {
const context = {
requestType: 'chatComplete',
request: {
json: {
messages: [
{ role: 'user', content: 'Hi' },
{ role: 'assistant', content: 'Hello, how can I help you?' },
],
},
},
response: {},
};

const parameters = {
credentials: testCreds,
text_type: 'prompt',
generic_safety_check: true,
greetings_list: ['Casual & Friendly', 'Professional & Polite'],
pii_list: ["Person's Name", 'Address'],
compliance_list: ['questions on medicine'],
};

const eventType = 'beforeRequestHook';

const result = await handler(context as any, parameters, eventType);
expect(result).toHaveProperty('verdict');
expect(result).toHaveProperty('data');
});
Comment on lines +103 to +131
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Code Refactor

Issue: New test case has hardcoded test data that could be extracted to constants
Fix: Consider extracting test messages and parameters to improve maintainability
Impact: Makes tests more readable and easier to maintain

The test looks comprehensive but could benefit from extracting the mock data to constants for better organization.

});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '../types';
import { post, getText, getCurrentContentPart } from '../utils';

const API_URL = 'https://services.walled.ai/v1/guardrail/moderate';
const API_URL = 'https://services.walled.ai/v1/walled-protect';

const DEFAULT_PII_LIST = [
"Person's Name",
Expand All @@ -18,7 +18,7 @@ const DEFAULT_PII_LIST = [
'Financial Data',
];

const DEFAULT_GREETINGS_LIST = ['Casual & Friendly', 'Professional & Polite'];
const DEFAULT_GREETINGS_LIST = ['Casual & Friendly'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Code Refactor

Issue: Default greetings list reduced from two options to one
Fix: Verify if 'Professional & Polite' option is no longer supported by the new API
Impact: May change default behavior for users who relied on both greeting styles

Suggested change
const DEFAULT_GREETINGS_LIST = ['Casual & Friendly'];
const DEFAULT_GREETINGS_LIST = ['Casual & Friendly'];


export const handler: PluginHandler = async (
context: PluginContext,
Expand All @@ -45,12 +45,14 @@ export const handler: PluginHandler = async (
data: null,
};
}
let text = textArray.filter((text) => text).join('\n');
let text = textArray
.filter((text) => text)
.join('\n')
.trim();
Comment on lines +48 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚡️ Performance Improvement

Issue: Text processing can be optimized with method chaining
Fix: Good improvement to add trim() and format the chain for better readability
Impact: Removes unnecessary whitespace and improves code maintainability

Suggested change
let text = textArray
.filter((text) => text)
.join('\n')
.trim();
let text = textArray
.filter((text) => text)
.join('\
')
.trim();


// Prepare request body
const requestBody = {
text: text,
text_type: parameters.text_type || 'prompt',
generic_safety_check: parameters.generic_safety_check ?? true,
Comment on lines 54 to 56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Code Refactor

Issue: Removed text_type parameter from request body without explanation
Fix: Consider documenting why this parameter was removed or if it's still needed for the new API
Impact: May affect API compatibility if the new endpoint expects this parameter

The removal of text_type parameter should be verified against the new API documentation to ensure compatibility.

greetings_list: parameters.greetings_list || DEFAULT_GREETINGS_LIST,
pii_list: parameters.pii_list || DEFAULT_PII_LIST,
Expand All @@ -60,7 +62,7 @@ export const handler: PluginHandler = async (
const requestOptions = {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${parameters.credentials.apiKey}`,
'x-api-key': parameters.credentials.apiKey,
},
};

Expand Down
Loading