A TypeScript/JavaScript SDK for interacting with Walled AI's Guardrail API.
Install via npm or yarn:
npm install walledai
# or
yarn add walledai
import { WalledProtect, PII } from 'walledai';
const guardrailClient = new WalledProtect({
apiKey: 'your_api_key_here',
retries: 3, // Optional, defaults to 3
timeout: 20000 // Optional, defaults to 20000 ms
});
const piiClient = new PII({
apiKey: 'your_api_key_here',
retries: 3, // Optional, defaults to 3
timeout: 20000 // Optional, defaults to 20000 ms
});
The Guardrail feature analyzes input text for safety, compliance, greetings, and PII, helping you moderate and filter user content according to your requirements.
const response = await guardrailClient.guardrail({
text: "Hello, how are you?",
greetingsList: ["generalgreetings"],
textType: "prompt", // Optional
genericSafetyCheck: true // Optional
});
console.log(response);
Parameter | Type | Required | Description |
---|---|---|---|
text |
string |
✅ Yes | Input text to analyze |
greetingsList |
string[] |
❌ No | List of greeting types (e.g. ["generalgreetings"] ) |
textType |
string |
❌ No | Type of text ("prompt" by default) |
genericSafetyCheck |
boolean |
❌ No | Enable general safety filtering (defaults to true ) |
{
"success": true,
"data": {
"safety": [{ "safety": "generic", "isSafe": true, "score": 5 }],
"compliance": [],
"pii": [],
"greetings": [{ "greeting_type": "generalgreetings", "isPresent": true }]
}
}
The PII feature detects and masks personally identifiable information (PII) such as emails, phone numbers, and more, replacing them with placeholders and providing a mapping for reference.
const piiResponse = await piiClient.pii("My email is [email protected] and my phone is 123-456-7890.");
console.log(piiResponse);
Parameter | Type | Required | Description |
---|---|---|---|
text |
string |
✅ Yes | Input text to process for PII masking |
{
"success": true,
"data": {
"success": true,
"remark": "PII masked successfully",
"input": "My email is [email protected] and my phone is 123-456-7890.",
"masked_text": "My email is PNA2 and my phone is PNA1.",
"mapping": {
"PNA2": "[email protected]",
"PNA1": "123-456-7890"
}
}
}
Both WalledProtect
and PII
accept the following config:
Parameter | Type | Required | Description |
---|---|---|---|
apiKey |
string |
✅ Yes | API key obtained from Walled AI |
retries |
number |
❌ No | Number of retry attempts on failure (default: 3 ) |
timeout |
number |
❌ No | Request timeout in milliseconds (default: 20000 ) |
If a request fails after retrying:
{
"success": false,
"error": "Network error or server failure message"
}
🔁 The SDK automatically retries requests that fail, up to the number of
retries
configured, with a delay between attempts.
MIT © Walled AI