A Python SDK for interacting with Walled AI.
pip install walledai
from walledai import WalledProtect
# Initialise the client
client = WalledProtect("your_api_key",retries=3)# retries is optional
response = client.guardrail(
text="Hello , How are you",
greetings_list=["generalgreetings"],
text_type="prompt",
generic_safety_check=True
)
print(response)
Processes the text using Walled AI's protection mechanisms.
text
(str, required): The input text to be processed.greetings_list
(list of str, optional): A list of predefined greetings categories.text_type
(str, optional): Type of text being processed. Defaults to"prompt"
.generic_safety_check
(bool, optional): Whether to apply a general safety filter. Defaults toTrue
.
response = client.guardrail(
text="Hello , How are you",
greetings_list=["generalgreetings"],
text_type="prompt",
generic_safety_check=True
)
print(response)
The response returned by the guardrail method is a dictionary.
{
"success": true,
"data": {
"safety": [{ "safety": "generic", "isSafe": true, "score": 5 }],
"compliance": [],
"pii": [],
"greetings": [{ "greeting_type": "generalgreetings", "isPresent": true }]
}
}
If an error occurs, the SDK will retry the request up to the specified number of retries (retries
parameter in WalledProtect
) or default retry number. If the retries are exhausted, it will return an error response.
{
"success": false,
"error": "Invalid API key provided."
}
Processes the text using Walled AI's PII mechanisms.
text
(str, required): The input text to be processed.
response = client.pii(
text="Hello , How are you Henry",
)
print(response)
The response returned by the guardrail method is a dictionary.
{
"success": true,
"data": {
"success": true,
"remark": "Success! one attempt",
"input": "Hi my name is Henry",
"masked_text": "Hello my name is PN1",
"mapping": {
"PNA1": "indranil"
}
}
}
If an error occurs, the SDK will retry the request up to the specified number of retries (retries
parameter in WalledProtect
) or default retry number. If the retries are exhausted, it will return an error response.
{
"success": false,
"error": "Invalid API key provided."
}