Skip to content

Commit a7783c7

Browse files
committed
refactor : walledprotect
1 parent 2c85290 commit a7783c7

File tree

4 files changed

+134
-98
lines changed

4 files changed

+134
-98
lines changed

plugins/index.ts

Lines changed: 95 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,107 @@
1-
import { handler as defaultregexMatch } from "./default/regexMatch"
2-
import { handler as defaultsentenceCount } from "./default/sentenceCount"
3-
import { handler as defaultwordCount } from "./default/wordCount"
4-
import { handler as defaultcharacterCount } from "./default/characterCount"
5-
import { handler as defaultjsonSchema } from "./default/jsonSchema"
6-
import { handler as defaultjsonKeys } from "./default/jsonKeys"
7-
import { handler as defaultcontains } from "./default/contains"
8-
import { handler as defaultvalidUrls } from "./default/validUrls"
9-
import { handler as defaultwebhook } from "./default/webhook"
10-
import { handler as defaultlog } from "./default/log"
11-
import { handler as defaultcontainsCode } from "./default/containsCode"
12-
import { handler as defaultalluppercase } from "./default/alluppercase"
13-
import { handler as defaultendsWith } from "./default/endsWith"
14-
import { handler as defaultalllowercase } from "./default/alllowercase"
15-
import { handler as defaultmodelwhitelist } from "./default/modelwhitelist"
16-
import { handler as defaultjwt } from "./default/jwt"
17-
import { handler as defaultrequiredMetadataKeys } from "./default/requiredMetadataKeys"
18-
import { handler as portkeymoderateContent } from "./portkey/moderateContent"
19-
import { handler as portkeylanguage } from "./portkey/language"
20-
import { handler as portkeypii } from "./portkey/pii"
21-
import { handler as portkeygibberish } from "./portkey/gibberish"
22-
import { handler as aporiavalidateProject } from "./aporia/validateProject"
23-
import { handler as sydelabssydeguard } from "./sydelabs/sydeguard"
24-
import { handler as pillarscanPrompt } from "./pillar/scanPrompt"
25-
import { handler as pillarscanResponse } from "./pillar/scanResponse"
26-
import { handler as patronusphi } from "./patronus/phi"
27-
import { handler as patronuspii } from "./patronus/pii"
28-
import { handler as patronusisConcise } from "./patronus/isConcise"
29-
import { handler as patronusisHelpful } from "./patronus/isHelpful"
30-
import { handler as patronusisPolite } from "./patronus/isPolite"
31-
import { handler as patronusnoApologies } from "./patronus/noApologies"
32-
import { handler as patronusnoGenderBias } from "./patronus/noGenderBias"
33-
import { handler as patronusnoRacialBias } from "./patronus/noRacialBias"
34-
import { handler as patronusretrievalAnswerRelevance } from "./patronus/retrievalAnswerRelevance"
35-
import { handler as patronustoxicity } from "./patronus/toxicity"
36-
import { handler as patronuscustom } from "./patronus/custom"
37-
import { handler as pangeatextGuard } from "./pangea/textGuard"
38-
import { handler as pangeapii } from "./pangea/pii"
39-
import { handler as promptsecurityprotectPrompt } from "./promptsecurity/protectPrompt"
40-
import { handler as promptsecurityprotectResponse } from "./promptsecurity/protectResponse"
41-
import { handler as panwPrismaAirsintercept } from "./panw-prisma-airs/intercept"
42-
import { handler as walledaiwalledprotect } from "./walledai/walledprotect"
1+
import { handler as defaultregexMatch } from './default/regexMatch';
2+
import { handler as defaultsentenceCount } from './default/sentenceCount';
3+
import { handler as defaultwordCount } from './default/wordCount';
4+
import { handler as defaultcharacterCount } from './default/characterCount';
5+
import { handler as defaultjsonSchema } from './default/jsonSchema';
6+
import { handler as defaultjsonKeys } from './default/jsonKeys';
7+
import { handler as defaultcontains } from './default/contains';
8+
import { handler as defaultvalidUrls } from './default/validUrls';
9+
import { handler as defaultwebhook } from './default/webhook';
10+
import { handler as defaultlog } from './default/log';
11+
import { handler as defaultcontainsCode } from './default/containsCode';
12+
import { handler as defaultalluppercase } from './default/alluppercase';
13+
import { handler as defaultendsWith } from './default/endsWith';
14+
import { handler as defaultalllowercase } from './default/alllowercase';
15+
import { handler as defaultmodelwhitelist } from './default/modelwhitelist';
16+
import { handler as defaultjwt } from './default/jwt';
17+
import { handler as defaultrequiredMetadataKeys } from './default/requiredMetadataKeys';
18+
import { handler as portkeymoderateContent } from './portkey/moderateContent';
19+
import { handler as portkeylanguage } from './portkey/language';
20+
import { handler as portkeypii } from './portkey/pii';
21+
import { handler as portkeygibberish } from './portkey/gibberish';
22+
import { handler as aporiavalidateProject } from './aporia/validateProject';
23+
import { handler as sydelabssydeguard } from './sydelabs/sydeguard';
24+
import { handler as pillarscanPrompt } from './pillar/scanPrompt';
25+
import { handler as pillarscanResponse } from './pillar/scanResponse';
26+
import { handler as patronusphi } from './patronus/phi';
27+
import { handler as patronuspii } from './patronus/pii';
28+
import { handler as patronusisConcise } from './patronus/isConcise';
29+
import { handler as patronusisHelpful } from './patronus/isHelpful';
30+
import { handler as patronusisPolite } from './patronus/isPolite';
31+
import { handler as patronusnoApologies } from './patronus/noApologies';
32+
import { handler as patronusnoGenderBias } from './patronus/noGenderBias';
33+
import { handler as patronusnoRacialBias } from './patronus/noRacialBias';
34+
import { handler as patronusretrievalAnswerRelevance } from './patronus/retrievalAnswerRelevance';
35+
import { handler as patronustoxicity } from './patronus/toxicity';
36+
import { handler as patronuscustom } from './patronus/custom';
37+
import { handler as pangeatextGuard } from './pangea/textGuard';
38+
import { handler as pangeapii } from './pangea/pii';
39+
import { handler as promptsecurityprotectPrompt } from './promptsecurity/protectPrompt';
40+
import { handler as promptsecurityprotectResponse } from './promptsecurity/protectResponse';
41+
import { handler as panwPrismaAirsintercept } from './panw-prisma-airs/intercept';
42+
import { handler as walledaiwalledprotect } from './walledai/walledprotect';
4343

4444
export const plugins = {
45-
"default": {
46-
"regexMatch": defaultregexMatch,
47-
"sentenceCount": defaultsentenceCount,
48-
"wordCount": defaultwordCount,
49-
"characterCount": defaultcharacterCount,
50-
"jsonSchema": defaultjsonSchema,
51-
"jsonKeys": defaultjsonKeys,
52-
"contains": defaultcontains,
53-
"validUrls": defaultvalidUrls,
54-
"webhook": defaultwebhook,
55-
"log": defaultlog,
56-
"containsCode": defaultcontainsCode,
57-
"alluppercase": defaultalluppercase,
58-
"endsWith": defaultendsWith,
59-
"alllowercase": defaultalllowercase,
60-
"modelwhitelist": defaultmodelwhitelist,
61-
"jwt": defaultjwt,
62-
"requiredMetadataKeys": defaultrequiredMetadataKeys
45+
default: {
46+
regexMatch: defaultregexMatch,
47+
sentenceCount: defaultsentenceCount,
48+
wordCount: defaultwordCount,
49+
characterCount: defaultcharacterCount,
50+
jsonSchema: defaultjsonSchema,
51+
jsonKeys: defaultjsonKeys,
52+
contains: defaultcontains,
53+
validUrls: defaultvalidUrls,
54+
webhook: defaultwebhook,
55+
log: defaultlog,
56+
containsCode: defaultcontainsCode,
57+
alluppercase: defaultalluppercase,
58+
endsWith: defaultendsWith,
59+
alllowercase: defaultalllowercase,
60+
modelwhitelist: defaultmodelwhitelist,
61+
jwt: defaultjwt,
62+
requiredMetadataKeys: defaultrequiredMetadataKeys,
6363
},
64-
"portkey": {
65-
"moderateContent": portkeymoderateContent,
66-
"language": portkeylanguage,
67-
"pii": portkeypii,
68-
"gibberish": portkeygibberish
64+
portkey: {
65+
moderateContent: portkeymoderateContent,
66+
language: portkeylanguage,
67+
pii: portkeypii,
68+
gibberish: portkeygibberish,
6969
},
70-
"aporia": {
71-
"validateProject": aporiavalidateProject
70+
aporia: {
71+
validateProject: aporiavalidateProject,
7272
},
73-
"sydelabs": {
74-
"sydeguard": sydelabssydeguard
73+
sydelabs: {
74+
sydeguard: sydelabssydeguard,
7575
},
76-
"pillar": {
77-
"scanPrompt": pillarscanPrompt,
78-
"scanResponse": pillarscanResponse
76+
pillar: {
77+
scanPrompt: pillarscanPrompt,
78+
scanResponse: pillarscanResponse,
7979
},
80-
"patronus": {
81-
"phi": patronusphi,
82-
"pii": patronuspii,
83-
"isConcise": patronusisConcise,
84-
"isHelpful": patronusisHelpful,
85-
"isPolite": patronusisPolite,
86-
"noApologies": patronusnoApologies,
87-
"noGenderBias": patronusnoGenderBias,
88-
"noRacialBias": patronusnoRacialBias,
89-
"retrievalAnswerRelevance": patronusretrievalAnswerRelevance,
90-
"toxicity": patronustoxicity,
91-
"custom": patronuscustom
80+
patronus: {
81+
phi: patronusphi,
82+
pii: patronuspii,
83+
isConcise: patronusisConcise,
84+
isHelpful: patronusisHelpful,
85+
isPolite: patronusisPolite,
86+
noApologies: patronusnoApologies,
87+
noGenderBias: patronusnoGenderBias,
88+
noRacialBias: patronusnoRacialBias,
89+
retrievalAnswerRelevance: patronusretrievalAnswerRelevance,
90+
toxicity: patronustoxicity,
91+
custom: patronuscustom,
9292
},
93-
"pangea": {
94-
"textGuard": pangeatextGuard,
95-
"pii": pangeapii
93+
pangea: {
94+
textGuard: pangeatextGuard,
95+
pii: pangeapii,
9696
},
97-
"promptsecurity": {
98-
"protectPrompt": promptsecurityprotectPrompt,
99-
"protectResponse": promptsecurityprotectResponse
97+
promptsecurity: {
98+
protectPrompt: promptsecurityprotectPrompt,
99+
protectResponse: promptsecurityprotectResponse,
100100
},
101-
"panw-prisma-airs": {
102-
"intercept": panwPrismaAirsintercept
101+
'panw-prisma-airs': {
102+
intercept: panwPrismaAirsintercept,
103+
},
104+
walledai: {
105+
walledprotect: walledaiwalledprotect,
103106
},
104-
"walledai": {
105-
"walledprotect": walledaiwalledprotect
106-
}
107107
};

plugins/walledai/manifest.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@
3838
"type": "array",
3939
"label": "Greetings List",
4040
"description": "List of greetings to be used in the guardrail check.",
41-
"items": { "type": "string" , "enum": ["Casual & Friendly", "Professional & Polite"] },
41+
"items": {
42+
"type": "string",
43+
"enum": ["Casual & Friendly", "Professional & Polite"]
44+
},
4245
"default": ["Casual & Friendly"]
4346
},
4447
"pii_list": {
@@ -65,7 +68,7 @@
6568
"Date Of Birth",
6669
"Unique Id",
6770
"Financial Data"
68-
]
71+
]
6972
},
7073
"compliance_list": {
7174
"type": "array",

plugins/walledai/walledai.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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/walledprotect.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ export const handler: PluginHandler = async (
4545
data: null,
4646
};
4747
}
48-
let text = textArray.filter((text) => text).join('\n').trim()
48+
let text = textArray
49+
.filter((text) => text)
50+
.join('\n')
51+
.trim();
4952

5053
// Prepare request body
5154
const requestBody = {

0 commit comments

Comments
 (0)