Skip to main content

Prompt Defender. A package to help you defend against prompt injection attacks.

Project description

README

Prompt Defender AWS Defences Library

Welcome to the Prompt Defender AWS Defences library. This library is designed to help you defend against prompt injection attacks by leveraging AWS services such as AWS Comprehend and SageMaker. The library is written in Python and can be easily installed via pip.

Installation

You can install the library using pip:

pip install prompt-defender-aws-defences

Usage

This library provides two main classes to help in detecting and preventing prompt injection attacks:

  1. AwsPIIScannerWallExecutor: This class uses AWS Comprehend to scan text for Personally Identifiable Information (PII).
  2. SagemakerWallExecutor: This class calls a remote SageMaker endpoint to validate the prompt.

Example

You can find example usage in the example.py file.

from prompt_defender_aws_defences import AwsPIIScannerWallExecutor, SagemakerWallExecutor

# Example usage of AwsPIIScannerWallExecutor
pii_executor = AwsPIIScannerWallExecutor()
validation_result = pii_executor.is_user_input_safe("Your text to scan here")
print(validation_result)

# Example usage of SagemakerWallExecutor
sagemaker_executor = SagemakerWallExecutor(sagemaker_name="your-sagemaker-endpoint")
validation_result = sagemaker_executor.is_user_input_safe("Your text to validate here")
print(validation_result)

Directory Structure

The main class files are located in the prompt_defender_aws_defences directory:

  • prompt_defender_aws_defences/__init__.py: Initializes the package and imports the main executors.
  • prompt_defender_aws_defences/wall/pii_detection.py: Contains the AwsPIIScanner and AwsPIIScannerWallExecutor classes.
  • prompt_defender_aws_defences/wall/sagemaker_inference.py: Contains the RemoteSagemakerCaller and SagemakerWallExecutor classes.
  • prompt_defender_aws_defences/wall/shared.py: Defines shared utilities such as MatchLevel and match_level_for_score.
  • prompt_defender_aws_defences/wall/__init__.py: Initializes the wall module and imports the necessary executors.

License

This project is licensed under the Apache License. See the LICENSE file for more details.

Contact

For any questions or issues, please contact the project owner at admin@safetorun.com.

Contributing

Contributions are welcome! Please refer to the project's GitHub Issues page for any open issues or feature requests.

Additional Information

For more details, please visit the project's Homepage.

We hope you find this library useful in defending against prompt injection attacks!


Happy coding! 🛡️

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prompt_defender_aws_defences-0.1.26.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page