Skip to content

Commit 2ef022d

Browse files
authored
Merge pull request #1263 from indranil786/main
Fix : WalledAI guardrail parameters
2 parents 01c2d5d + 2a16ebb commit 2ef022d

File tree

3 files changed

+52
-9
lines changed

3 files changed

+52
-9
lines changed

plugins/walledai/guardrails.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ import { post, getText, getCurrentContentPart } from '../utils';
88

99
const API_URL = 'https://services.walled.ai/v1/guardrail/moderate';
1010

11+
const DEFAULT_PII_LIST = [
12+
"Person's Name",
13+
'Address',
14+
'Email Id',
15+
'Contact No',
16+
'Date Of Birth',
17+
'Unique Id',
18+
'Financial Data',
19+
];
20+
21+
const DEFAULT_GREETINGS_LIST = ['Casual & Friendly', 'Professional & Polite'];
22+
1123
export const handler: PluginHandler = async (
1224
context: PluginContext,
1325
parameters: PluginParameters,
@@ -40,13 +52,15 @@ export const handler: PluginHandler = async (
4052
text: text,
4153
text_type: parameters.text_type || 'prompt',
4254
generic_safety_check: parameters.generic_safety_check ?? true,
43-
greetings_list: parameters.greetings_list || ['generalgreetings'],
55+
greetings_list: parameters.greetings_list || DEFAULT_GREETINGS_LIST,
56+
pii_list: parameters.pii_list || DEFAULT_PII_LIST,
57+
compliance_list: parameters.compliance_list || [],
4458
};
4559
// Prepare headers
4660
const requestOptions = {
4761
headers: {
4862
'Content-Type': 'application/json',
49-
Authorization: `Bearer ${parameters.credentials.apiKey}`, // Uncomment if API key is required
63+
Authorization: `Bearer ${parameters.credentials.apiKey}`,
5064
},
5165
};
5266

plugins/walledai/manifest.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@
6060
}
6161
],
6262
"items": {
63-
"type": "string",
64-
"default": ["generalgreetings"]
65-
}
63+
"type": "string"
64+
},
65+
"default": ["Casual & Friendly", "Professional & Polite"]
6666
},
6767
"pii_list": {
6868
"type": "array",
@@ -84,7 +84,16 @@
8484
"Unique Id",
8585
"Financial Data"
8686
]
87-
}
87+
},
88+
"default": [
89+
"Person's Name",
90+
"Address",
91+
"Email Id",
92+
"Contact No",
93+
"Date Of Birth",
94+
"Unique Id",
95+
"Financial Data"
96+
]
8897
},
8998
"compliance_list": {
9099
"type": "array",
@@ -97,7 +106,8 @@
97106
],
98107
"items": {
99108
"type": "string"
100-
}
109+
},
110+
"default": []
101111
}
102112
}
103113
}

plugins/walledai/walledai.test.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ describe('WalledAI Guardrail Plugin Handler (integration)', () => {
1111
credentials: testCreds,
1212
text_type: 'prompt',
1313
generic_safety_check: true,
14-
greetings_list: ['generalgreetings'],
14+
greetings_list: ['Casual & Friendly', 'Professional & Polite'],
1515
pii_list: ["Person's Name", 'Address'],
16-
compliance_list: [],
16+
compliance_list: ['questions on medicine'],
1717
};
1818

1919
const makeContext = (text: string): PluginContext => ({
@@ -80,4 +80,23 @@ describe('WalledAI Guardrail Plugin Handler (integration)', () => {
8080
expect(result.verdict).toBe(true);
8181
expect(result.error).toBeNull();
8282
});
83+
84+
it('handles compliance_list parameter', async () => {
85+
const context = makeContext('This is a test for compliance.');
86+
87+
const paramsWithCompliance: PluginParameters = {
88+
...baseParams,
89+
compliance_list: ['GDPR', 'PCI-DSS'],
90+
};
91+
92+
const result = await handler(
93+
context,
94+
paramsWithCompliance,
95+
'beforeRequestHook'
96+
);
97+
98+
expect(result.error).toBeNull();
99+
expect(result.data).toBeDefined();
100+
// Optionally, check if compliance_list was respected in the response if API supports it
101+
});
83102
});

0 commit comments

Comments
 (0)