Skip to content

walledai/walledai-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Walled AI SDK

A Python SDK for interacting with Walled AI.

Installation

pip install walledai

Usage

from walledai import WalledProtect
# Initialise the client 
client = WalledProtect("your_api_key",retries=3)# retries is optional

Walled Protect

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.

Parameters:

  • 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 to True.

Example Usage:

response = client.guardrail(
    text="Hello , How are you", 
    greetings_list=["generalgreetings"], 
    text_type="prompt", 
    generic_safety_check=True
)
print(response)

Example Responses

The response returned by the guardrail method is a dictionary.

Successful Response

{
    "success": true,
    "data": {
        "safety": [{ "safety": "generic", "isSafe": true, "score": 5 }],
        "compliance": [],
        "pii": [],
        "greetings": [{ "greeting_type": "generalgreetings", "isPresent": true }]
    }
}

Error Response

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."
}

PII

Processes the text using Walled AI's PII mechanisms.

Parameters:

  • text (str, required): The input text to be processed.

Example Usage:

response = client.pii(
    text="Hello , How are you Henry", 
)
print(response)

Example Responses

The response returned by the guardrail method is a dictionary.

Successful Response

{
    "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"
        }
    }
}

Error Response

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."
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages