Skip to content

Commit 128280c

Browse files
authored
Merge pull request #1316 from indranil786/main
Fix : Walled Ai Guardrail changed to walledprotect
2 parents a2c0ad4 + f8a0f44 commit 128280c

File tree

4 files changed

+49
-49
lines changed

4 files changed

+49
-49
lines changed

plugins/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import { handler as promptSecurityProtectResponse } from './promptsecurity/prote
6262
import { handler as panwPrismaAirsintercept } from './panw-prisma-airs/intercept';
6363
import { handler as defaultjwt } from './default/jwt';
6464
import { handler as defaultrequiredMetadataKeys } from './default/requiredMetadataKeys';
65-
import { handler as walledaiguardrails } from './walledai/guardrails';
65+
import { handler as walledaiguardrails } from './walledai/walledprotect';
6666
import { handler as defaultregexReplace } from './default/regexReplace';
6767
import { handler as defaultallowedRequestTypes } from './default/allowedRequestTypes';
6868
import { handler as javelinguardrails } from './javelin/guardrails';
@@ -169,7 +169,7 @@ export const plugins = {
169169
intercept: panwPrismaAirsintercept,
170170
},
171171
walledai: {
172-
guardrails: walledaiguardrails,
172+
walledprotect: walledaiguardrails,
173173
},
174174
javelin: {
175175
guardrails: javelinguardrails,

plugins/walledai/manifest.json

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"functions": [
1717
{
1818
"name": "Walled AI Guardrail for checking safety of LLM inputs",
19-
"id": "guardrails",
19+
"id": "walledprotect",
2020
"supportedHooks": ["beforeRequestHook", "afterRequestHook"],
2121
"type": "guardrail",
2222
"description": [
@@ -28,51 +28,26 @@
2828
"parameters": {
2929
"type": "object",
3030
"properties": {
31-
"text_type": {
32-
"type": "string",
33-
"label": "Text Type",
34-
"description": [
35-
{
36-
"type": "subHeading",
37-
"text": "Type of Text , defaults to 'prompt'"
38-
}
39-
],
40-
"default": "prompt"
41-
},
4231
"generic_safety_check": {
4332
"type": "string",
4433
"label": "Generic Safety Check",
45-
"description": [
46-
{
47-
"type": "subHeading",
48-
"text": "Boolean value to enable generic safety checks on the text input. Defaults to 'true'."
49-
}
50-
],
34+
"description": "Boolean value to enable generic safety checks on the text input. Defaults to 'true'.",
5135
"default": true
5236
},
5337
"greetings_list": {
5438
"type": "array",
5539
"label": "Greetings List",
56-
"description": [
57-
{
58-
"type": "subHeading",
59-
"text": "List of greetings to be used in the guardrail check. This can help in identifying and handling greetings appropriately."
60-
}
61-
],
40+
"description": "List of greetings to be used in the guardrail check.",
6241
"items": {
63-
"type": "string"
42+
"type": "string",
43+
"enum": ["Casual & Friendly", "Professional & Polite"]
6444
},
65-
"default": ["Casual & Friendly", "Professional & Polite"]
45+
"default": ["Casual & Friendly"]
6646
},
6747
"pii_list": {
6848
"type": "array",
6949
"label": "PII LIST",
70-
"description": [
71-
{
72-
"type": "subHeading",
73-
"text": "Identify all the PII for only the following types of PII will be checked in the text input. Defaults to empty list"
74-
}
75-
],
50+
"description": "PII types that should be checked in the input text.",
7651
"items": {
7752
"type": "string",
7853
"enum": [
@@ -98,15 +73,8 @@
9873
"compliance_list": {
9974
"type": "array",
10075
"label": "List of Compliance Checks",
101-
"description": [
102-
{
103-
"type": "subHeading",
104-
"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"
105-
}
106-
],
107-
"items": {
108-
"type": "string"
109-
},
76+
"description": "Compliance checks to be performed on the text input.",
77+
"items": { "type": "string" },
11078
"default": []
11179
}
11280
}

plugins/walledai/walledai.test.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { handler } from './guardrails';
1+
import { handler } from './walledprotect';
22
import testCredsFile from './creds.json';
33
import { HookEventType, PluginContext, PluginParameters } from '../types';
44

@@ -99,4 +99,34 @@ describe('WalledAI Guardrail Plugin Handler (integration)', () => {
9999
expect(result.data).toBeDefined();
100100
// Optionally, check if compliance_list was respected in the response if API supports it
101101
});
102+
103+
it('should handle conversational text format', async () => {
104+
const context = {
105+
requestType: 'chatComplete',
106+
request: {
107+
json: {
108+
messages: [
109+
{ role: 'user', content: 'Hi' },
110+
{ role: 'assistant', content: 'Hello, how can I help you?' },
111+
],
112+
},
113+
},
114+
response: {},
115+
};
116+
117+
const parameters = {
118+
credentials: testCreds,
119+
text_type: 'prompt',
120+
generic_safety_check: true,
121+
greetings_list: ['Casual & Friendly', 'Professional & Polite'],
122+
pii_list: ["Person's Name", 'Address'],
123+
compliance_list: ['questions on medicine'],
124+
};
125+
126+
const eventType = 'beforeRequestHook';
127+
128+
const result = await handler(context as any, parameters, eventType);
129+
expect(result).toHaveProperty('verdict');
130+
expect(result).toHaveProperty('data');
131+
});
102132
});

plugins/walledai/guardrails.ts renamed to plugins/walledai/walledprotect.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from '../types';
77
import { post, getText, getCurrentContentPart } from '../utils';
88

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

1111
const DEFAULT_PII_LIST = [
1212
"Person's Name",
@@ -18,7 +18,7 @@ const DEFAULT_PII_LIST = [
1818
'Financial Data',
1919
];
2020

21-
const DEFAULT_GREETINGS_LIST = ['Casual & Friendly', 'Professional & Polite'];
21+
const DEFAULT_GREETINGS_LIST = ['Casual & Friendly'];
2222

2323
export const handler: PluginHandler = async (
2424
context: PluginContext,
@@ -45,12 +45,14 @@ export const handler: PluginHandler = async (
4545
data: null,
4646
};
4747
}
48-
let text = textArray.filter((text) => text).join('\n');
48+
let text = textArray
49+
.filter((text) => text)
50+
.join('\n')
51+
.trim();
4952

5053
// Prepare request body
5154
const requestBody = {
5255
text: text,
53-
text_type: parameters.text_type || 'prompt',
5456
generic_safety_check: parameters.generic_safety_check ?? true,
5557
greetings_list: parameters.greetings_list || DEFAULT_GREETINGS_LIST,
5658
pii_list: parameters.pii_list || DEFAULT_PII_LIST,
@@ -60,7 +62,7 @@ export const handler: PluginHandler = async (
6062
const requestOptions = {
6163
headers: {
6264
'Content-Type': 'application/json',
63-
Authorization: `Bearer ${parameters.credentials.apiKey}`,
65+
'x-api-key': parameters.credentials.apiKey,
6466
},
6567
};
6668

0 commit comments

Comments
 (0)