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}
}
Metadata
Release files for safenudge 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| safenudge-0.1.0.tar.gz | 44.5 kB | Without provenance | Details for safenudge-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| safenudge-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for safenudge-0.1.0-py3-none-any.whl |
Total release size: 99.7 kB
Release files / safenudge-0.1.0.tar.gz
| Download URL | safenudge-0.1.0.tar.gz |
|---|---|
| Size | 44.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e41338f73eb8841f38d690447afe83b59d92f79ef20a1c19d779d576b677eb5f
|
|
BLAKE2b-256 checksum How to use checksums |
e7d730e8432601c8a3e9d751b75e74241803956b5867796a14b45ce17ea902cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.23
|
Release files / safenudge-0.1.0-py3-none-any.whl
| Download URL | safenudge-0.1.0-py3-none-any.whl |
|---|---|
| Size | 55.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8df4539a93211cb938bba7ae7c8fdcb905df23cc0aaec432608e7736c6d60cb5
|
|
BLAKE2b-256 checksum How to use checksums |
af3131b49077887d49d5072a0c8921528c9941d985806561e92357983ea3370a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.23
|
Security for safenudge 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.