Skip to content

Commit 2c85290

Browse files
committed
refactor : walledai guardrail hanged to walledprotect
1 parent a4bf25c commit 2c85290

File tree

4 files changed

+118
-190
lines changed

4 files changed

+118
-190
lines changed

plugins/index.ts

Lines changed: 104 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,143 +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 defaultalllowercase } from './default/alllowercase';
14-
import { handler as defaultendsWith } from './default/endsWith';
15-
import { handler as defaultmodelWhitelist } from './default/modelWhitelist';
16-
import { handler as portkeymoderateContent } from './portkey/moderateContent';
17-
import { handler as portkeylanguage } from './portkey/language';
18-
import { handler as portkeypii } from './portkey/pii';
19-
import { handler as portkeygibberish } from './portkey/gibberish';
20-
import { handler as aporiavalidateProject } from './aporia/validateProject';
21-
import { handler as sydelabssydeguard } from './sydelabs/sydeguard';
22-
import { handler as pillarscanPrompt } from './pillar/scanPrompt';
23-
import { handler as pillarscanResponse } from './pillar/scanResponse';
24-
import { handler as patronusphi } from './patronus/phi';
25-
import { handler as patronuspii } from './patronus/pii';
26-
import { handler as patronusisConcise } from './patronus/isConcise';
27-
import { handler as patronusisHelpful } from './patronus/isHelpful';
28-
import { handler as patronusisPolite } from './patronus/isPolite';
29-
import { handler as patronusnoApologies } from './patronus/noApologies';
30-
import { handler as patronusnoGenderBias } from './patronus/noGenderBias';
31-
import { handler as patronusnoRacialBias } from './patronus/noRacialBias';
32-
import { handler as patronusretrievalAnswerRelevance } from './patronus/retrievalAnswerRelevance';
33-
import { handler as patronustoxicity } from './patronus/toxicity';
34-
import { handler as patronuscustom } from './patronus/custom';
35-
import { mistralGuardrailHandler } from './mistral';
36-
import { handler as pangeatextGuard } from './pangea/textGuard';
37-
import { handler as promptfooPii } from './promptfoo/pii';
38-
import { handler as promptfooHarm } from './promptfoo/harm';
39-
import { handler as promptfooGuard } from './promptfoo/guard';
40-
import { handler as pangeapii } from './pangea/pii';
41-
import { pluginHandler as bedrockHandler } from './bedrock/index';
42-
import { handler as acuvityScan } from './acuvity/scan';
43-
import { handler as lassoclassify } from './lasso/classify';
44-
import { handler as exaonline } from './exa/online';
45-
import { handler as azurePii } from './azure/pii';
46-
import { handler as azureContentSafety } from './azure/contentSafety';
47-
import { handler as promptSecurityProtectPrompt } from './promptsecurity/protectPrompt';
48-
import { handler as promptSecurityProtectResponse } from './promptsecurity/protectResponse';
49-
import { handler as panwPrismaAirsintercept } from './panw-prisma-airs/intercept';
50-
import { handler as defaultjwt } from './default/jwt';
51-
import { handler as defaultrequiredMetadataKeys } from './default/requiredMetadataKeys';
52-
import { handler as walledaiguardrails } from './walledai/guardrails';
53-
import { handler as defaultregexReplace } from './default/regexReplace';
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"
5443

5544
export const plugins = {
56-
default: {
57-
regexMatch: defaultregexMatch,
58-
sentenceCount: defaultsentenceCount,
59-
wordCount: defaultwordCount,
60-
characterCount: defaultcharacterCount,
61-
jsonSchema: defaultjsonSchema,
62-
jsonKeys: defaultjsonKeys,
63-
contains: defaultcontains,
64-
validUrls: defaultvalidUrls,
65-
webhook: defaultwebhook,
66-
log: defaultlog,
67-
containsCode: defaultcontainsCode,
68-
alluppercase: defaultalluppercase,
69-
alllowercase: defaultalllowercase,
70-
endsWith: defaultendsWith,
71-
modelWhitelist: defaultmodelWhitelist,
72-
jwt: defaultjwt,
73-
requiredMetadataKeys: defaultrequiredMetadataKeys,
74-
regexReplace: defaultregexReplace,
75-
},
76-
portkey: {
77-
moderateContent: portkeymoderateContent,
78-
language: portkeylanguage,
79-
pii: portkeypii,
80-
gibberish: portkeygibberish,
81-
},
82-
aporia: {
83-
validateProject: aporiavalidateProject,
84-
},
85-
sydelabs: {
86-
sydeguard: sydelabssydeguard,
87-
},
88-
pillar: {
89-
scanPrompt: pillarscanPrompt,
90-
scanResponse: pillarscanResponse,
91-
},
92-
patronus: {
93-
phi: patronusphi,
94-
pii: patronuspii,
95-
isConcise: patronusisConcise,
96-
isHelpful: patronusisHelpful,
97-
isPolite: patronusisPolite,
98-
noApologies: patronusnoApologies,
99-
noGenderBias: patronusnoGenderBias,
100-
noRacialBias: patronusnoRacialBias,
101-
retrievalAnswerRelevance: patronusretrievalAnswerRelevance,
102-
toxicity: patronustoxicity,
103-
custom: patronuscustom,
104-
},
105-
mistral: {
106-
moderateContent: mistralGuardrailHandler,
107-
},
108-
pangea: {
109-
textGuard: pangeatextGuard,
110-
pii: pangeapii,
111-
},
112-
promptfoo: {
113-
pii: promptfooPii,
114-
harm: promptfooHarm,
115-
guard: promptfooGuard,
116-
},
117-
bedrock: {
118-
guard: bedrockHandler,
119-
},
120-
acuvity: {
121-
scan: acuvityScan,
122-
},
123-
lasso: {
124-
classify: lassoclassify,
125-
},
126-
exa: {
127-
online: exaonline,
128-
},
129-
azure: {
130-
pii: azurePii,
131-
contentSafety: azureContentSafety,
132-
},
133-
promptsecurity: {
134-
protectPrompt: promptSecurityProtectPrompt,
135-
protectResponse: promptSecurityProtectResponse,
136-
},
137-
'panw-prisma-airs': {
138-
intercept: panwPrismaAirsintercept,
139-
},
140-
walledai: {
141-
guardrails: walledaiguardrails,
142-
},
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
63+
},
64+
"portkey": {
65+
"moderateContent": portkeymoderateContent,
66+
"language": portkeylanguage,
67+
"pii": portkeypii,
68+
"gibberish": portkeygibberish
69+
},
70+
"aporia": {
71+
"validateProject": aporiavalidateProject
72+
},
73+
"sydelabs": {
74+
"sydeguard": sydelabssydeguard
75+
},
76+
"pillar": {
77+
"scanPrompt": pillarscanPrompt,
78+
"scanResponse": pillarscanResponse
79+
},
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
92+
},
93+
"pangea": {
94+
"textGuard": pangeatextGuard,
95+
"pii": pangeapii
96+
},
97+
"promptsecurity": {
98+
"protectPrompt": promptsecurityprotectPrompt,
99+
"protectResponse": promptsecurityprotectResponse
100+
},
101+
"panw-prisma-airs": {
102+
"intercept": panwPrismaAirsintercept
103+
},
104+
"walledai": {
105+
"walledprotect": walledaiwalledprotect
106+
}
143107
};

plugins/walledai/manifest.json

Lines changed: 9 additions & 44 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,23 @@
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-
],
62-
"items": {
63-
"type": "string"
64-
},
65-
"default": ["Casual & Friendly", "Professional & Polite"]
40+
"description": "List of greetings to be used in the guardrail check.",
41+
"items": { "type": "string" , "enum": ["Casual & Friendly", "Professional & Polite"] },
42+
"default": ["Casual & Friendly"]
6643
},
6744
"pii_list": {
6845
"type": "array",
6946
"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-
],
47+
"description": "PII types that should be checked in the input text.",
7648
"items": {
7749
"type": "string",
7850
"enum": [
@@ -93,20 +65,13 @@
9365
"Date Of Birth",
9466
"Unique Id",
9567
"Financial Data"
96-
]
68+
]
9769
},
9870
"compliance_list": {
9971
"type": "array",
10072
"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-
},
73+
"description": "Compliance checks to be performed on the text input.",
74+
"items": { "type": "string" },
11075
"default": []
11176
}
11277
}

plugins/walledai/walledai.test.ts

Lines changed: 1 addition & 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

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

Lines changed: 4 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,11 @@ export const handler: PluginHandler = async (
4545
data: null,
4646
};
4747
}
48-
let text = textArray.filter((text) => text).join('\n');
48+
let text = textArray.filter((text) => text).join('\n').trim()
4949

5050
// Prepare request body
5151
const requestBody = {
5252
text: text,
53-
text_type: parameters.text_type || 'prompt',
5453
generic_safety_check: parameters.generic_safety_check ?? true,
5554
greetings_list: parameters.greetings_list || DEFAULT_GREETINGS_LIST,
5655
pii_list: parameters.pii_list || DEFAULT_PII_LIST,
@@ -60,7 +59,7 @@ export const handler: PluginHandler = async (
6059
const requestOptions = {
6160
headers: {
6261
'Content-Type': 'application/json',
63-
Authorization: `Bearer ${parameters.credentials.apiKey}`,
62+
'x-api-key': parameters.credentials.apiKey,
6463
},
6564
};
6665

0 commit comments

Comments
 (0)