Skip to main content

A Python library with the implementation for the algorithms used in 'Safeguarding large language models in real-time with tunable safety-performance trade-offs', by J. Fonseca, A. Bell and J. Stoyanovich.

Project description

SafeNudge

A Python library with the implementation for the algorithms used in "Safeguarding large language models in real-time with tunable safety-performance trade-offs", by J. Fonseca, A. Bell and J. Stoyanovich.

CTG provides methods to guide model responses based on various criteria, helping ensure safe, high-quality, and controllable text generation.

Implemented methods

  • Controlled Text Generation (CTG): The SafeNudge implementation.
  • WildGuard Integration (WildguardCTG): SafeNudge using the WildGuard classifier
  • Token Masking (TokenMaskingCTG): c-FUDGE, as described in the paper

Installation

A Python distribution of version >= 3.12 is required to run this project. Earlier Python versions might work in most cases, but they were never tested.

From Source

# Clone the repository
git clone https://github.com/joaopfonseca/SafeNudge.git
cd Output-Steering

# Install in development mode
pip install -e .

Using pip

pip install git+https://github.com/joaopfonseca/SafeNudge.git

Examples

Check the notebooks directory for some examples Andrew and I developed while working on SafeNudge and setting up the experiments!

Project Structure

Output-Steering/
├── ctg/                    # Core library code
├── experiments/            # Experimental code and evaluation
└── notebooks/              # Jupyter notebooks with examples

License

This project is licensed under the MIT License - see the LICENSE file for details.

Citation

If you use this code in your research, please cite:

@article{fonseca2025safeguarding,
  title={Safeguarding large language models in real-time with tunable safety-performance trade-offs},
  author={Fonseca, Joao and Bell, Andrew and Stoyanovich, Julia},
  journal={arXiv preprint arXiv:2501.02018},
  year={2025}
}

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

safenudge-0.1.0.tar.gz (44.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

safenudge-0.1.0-py3-none-any.whl (55.2 kB view details)

Uploaded Python 3

File details

Details for the file safenudge-0.1.0.tar.gz.

File metadata

  • Download URL: safenudge-0.1.0.tar.gz
  • Upload date:
  • Size: 44.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.23

File hashes

Hashes for safenudge-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e41338f73eb8841f38d690447afe83b59d92f79ef20a1c19d779d576b677eb5f
MD5 8f03fb794b26cbf21ecb6727b224be25
BLAKE2b-256 e7d730e8432601c8a3e9d751b75e74241803956b5867796a14b45ce17ea902cd

See more details on using hashes here.

File details

Details for the file safenudge-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: safenudge-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 55.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.23

File hashes

Hashes for safenudge-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8df4539a93211cb938bba7ae7c8fdcb905df23cc0aaec432608e7736c6d60cb5
MD5 38aacb47f639f3c001b0d96a475507af
BLAKE2b-256 af3131b49077887d49d5072a0c8921528c9941d985806561e92357983ea3370a

See more details on using hashes here.

Supported by

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