Skip to main content

Security and moderation tools for the Jazzmine AI ecosystem

Project description

Jazzmine Security

Production-ready security and moderation toolkit for AI applications

Python 3.10+ PyPI version License: MIT

Jazzmine Security provides a comprehensive suite of tools for protecting AI applications from malicious inputs, toxic outputs, and unsafe content. Built with performance in mind, it combines Python flexibility with Rust speed through optimized bindings.

Features

Input Moderation

  • Jailbreak Detection: Identify and block prompt injection attacks
  • Toxic Content Detection: Multi-class toxicity classification with SHAP explainability
  • Batch Processing: High-throughput classification with GPU acceleration
  • HuggingFace Integration: Load pre-trained models directly from the Hub

Output Moderation

  • Response Validation: Ensure AI-generated content meets safety guidelines
  • Chunk-based Analysis: Handle long-form content with intelligent chunking
  • Confidence Scoring: Get detailed confidence metrics for each prediction

Content Sanitization

  • PDF Sanitization: Remove JavaScript, embedded files, and malicious content
  • CSV Sanitization: Prevent formula injection and XSS attacks
  • HTML Sanitization: Strip dangerous tags and attributes while preserving content

Performance

  • Rust-Powered: Critical text processing operations accelerated with Rust
  • GPU Support: Automatic CUDA acceleration when available
  • Async Support: Non-blocking operations for high-concurrency environments

Installation

From PyPI (Recommended)

pip install jazzmine-security

With GPU Support

pip install jazzmine-security torch --index-url https://download.pytorch.org/whl/cu121

From Source

git clone https://github.com/yourorg/jazzmine-security.git
cd jazzmine-security
pip install .

Quick Start

Input Moderation

from jazzmine.security import JazzmineInputModerator
from jazzmine.logging import ConsoleLogger

# Initialize with HuggingFace model
logger = ConsoleLogger()
moderator = JazzmineInputModerator(
    "nourmedini1/jazzmine-input-safeguard-v2",
    logger=logger
)

# Classify single input
text = "How can I hack into a system?"
label, confidence = moderator.classify(text)

if label == "LABEL_1":  # Toxic/Jailbreak detected
    print(f"Warning: Blocked - Confidence {confidence:.2%}")
else:
    print(f"Safe: Confidence {confidence:.2%}")

# Batch processing
requests = [
    {"text": "Tell me a joke"},
    {"text": "How to bypass security"},
    {"text": "What's the weather like?"}
]
results = moderator.classify_batch(requests, batch_size=32)

Output Moderation

from jazzmine.security import JazzmineOutputModerator

# Initialize output validator
output_mod = JazzmineOutputModerator(
    "nourmedini1/jazzmine-response-validator-v2"
)

# Validate AI response
ai_response = "Here's how to create a secure password..."
label, confidence = output_mod.classify(ai_response)

if label == "LABEL_1":  # Unsafe content
    print("Response blocked due to safety concerns")
else:
    print("Response approved")

Content Sanitization

from jazzmine.security import (
    JazzminePDFSanitizer,
    JazzmineCSVSanitizer,
    JazzmineHTMLSanitizer
)

# Sanitize PDF
pdf_sanitizer = JazzminePDFSanitizer()
safe_pdf = pdf_sanitizer.sanitize("document.pdf")

# Sanitize CSV (prevent formula injection)
csv_sanitizer = JazzmineCSVSanitizer()
safe_csv = csv_sanitizer.sanitize("data.csv")

# Sanitize HTML
html_sanitizer = JazzmineHTMLSanitizer()
safe_html = html_sanitizer.sanitize("<script>alert('xss')</script><p>Safe content</p>")
# Output: "<p>Safe content</p>"

Toxicity Detection with Explainability

from jazzmine.security.toxic_content_detector import JazzmineToxicityDetector

# Initialize detector
detector = JazzmineToxicityDetector()

# Train on your data
detector.train(
    csv_path="training_data.csv",
    text_column="text",
    label_column="is_toxic"
)

# Make predictions
text = "This is a test message"
prediction = detector.predict(text)
print(f"Toxic: {prediction['is_toxic']}")
print(f"Confidence: {prediction['confidence']:.2%}")

# Get SHAP explanations
explanation = detector.explain(text, num_samples=100)
print(f"Top contributing features: {explanation['top_features']}")

Architecture

Jazzmine Security is built with a hybrid Python-Rust architecture:

  • Python Layer: High-level APIs, model management, ML workflows
  • Rust Layer: Text normalization, TF-IDF extraction, semantic analysis
  • HuggingFace Integration: Seamless model loading and caching
  • PyO3 Bindings: Zero-copy data transfer between Python and Rust

Models

Pre-trained Models on HuggingFace

  • Input Safeguard: nourmedini1/jazzmine-input-safeguard-v2

    • Detects jailbreaks, prompt injections, and malicious inputs
    • Fine-tuned on diverse attack patterns
  • Response Validator: nourmedini1/jazzmine-response-validator-v2

    • Validates AI-generated content for safety
    • Identifies unsafe, biased, or harmful outputs

Custom Models

You can train and use your own models:

from jazzmine.security.toxic_content_detector import JazzmineToxicityDetector

detector = JazzmineToxicityDetector()
detector.train("your_data.csv", text_column="text", label_column="label")
detector.save("my_custom_model")

# Later use
detector = JazzmineToxicityDetector()
detector.load("my_custom_model")

Configuration

Logging Integration

from jazzmine.logging import BaseLogger, RequestContext

class MyLogger(BaseLogger):
    def info(self, message: str, **kwargs):
        print(f"[INFO] {message}: {kwargs}")

moderator = JazzmineInputModerator(
    "nourmedini1/jazzmine-input-safeguard-v2",
    logger=MyLogger()
)

GPU Configuration

import torch

# Check GPU availability
if torch.cuda.is_available():
    print(f"Using GPU: {torch.cuda.get_device_name(0)}")
else:
    print("Using CPU")

# Models automatically use GPU when available

Chunking Configuration

moderator = JazzmineInputModerator("model-name")

# Adjust chunk size for long texts
moderator.chunk_size = 512  # tokens
moderator.overlap = 50      # token overlap between chunks

Testing

# Run all tests
pytest tests/

# Run with coverage
pytest --cov=jazzmine.security tests/

# Run specific test file
pytest tests/test_input_moderator.py

Performance

Benchmark on NVIDIA RTX 3090:

Operation Throughput Latency (p50) Latency (p99)
Input Moderation (batch=32) 450 texts/sec 71ms 120ms
Output Validation (batch=32) 420 texts/sec 76ms 130ms
Toxicity Detection 800 texts/sec 1.2ms 5ms
PDF Sanitization 15 docs/sec 65ms 150ms

Contributing

We welcome contributions! Please see our Contributing Guide for details.

# Setup development environment
git clone https://github.com/yourorg/jazzmine-security.git
cd jazzmine-security
pip install -e ".[dev]"

# Build Rust components
cd bindings
maturin develop --release

# Run tests
pytest tests/

License

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

Acknowledgments

Support

Roadmap

  • Multi-language support (French, Arabic, Spanish)
  • Real-time monitoring dashboard
  • Additional sanitizers (JSON, XML, Markdown)
  • Model distillation for edge deployment
  • Integration with popular LLM frameworks (LangChain, LlamaIndex)

Made with care by the Jazzmine Team

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

jazzmine_security-0.1.6.tar.gz (2.4 MB view details)

Uploaded Source

Built Distributions

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

jazzmine_security-0.1.6-cp38-abi3-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.8+Windows x86-64

jazzmine_security-0.1.6-cp38-abi3-manylinux_2_34_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.34+ x86-64

jazzmine_security-0.1.6-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

jazzmine_security-0.1.6-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

jazzmine_security-0.1.6-cp38-abi3-macosx_11_0_arm64.whl (3.8 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

jazzmine_security-0.1.6-cp38-abi3-macosx_10_12_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file jazzmine_security-0.1.6.tar.gz.

File metadata

  • Download URL: jazzmine_security-0.1.6.tar.gz
  • Upload date:
  • Size: 2.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for jazzmine_security-0.1.6.tar.gz
Algorithm Hash digest
SHA256 37ec97a2a4debcea0c2df872bc1563c9fcf727841ff1602dbe8c8b75db52aa5d
MD5 2175ad60ef51cc77631c36df9f23a3ba
BLAKE2b-256 0627e5756956b72ce6dca6a8d7a3dfedeeafb008b41b0101899afe78e68ffa5f

See more details on using hashes here.

File details

Details for the file jazzmine_security-0.1.6-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jazzmine_security-0.1.6-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7892118c9ada0164926e4c114f666ea68c308181ec7973ca8b74e049434e7bb3
MD5 9408b12a838e4348f6f1d68cdad9620d
BLAKE2b-256 96d4fc6aebdbc0190039987e4d6cbfd074a91acbd8fe6d426311fec6fc76ef3e

See more details on using hashes here.

File details

Details for the file jazzmine_security-0.1.6-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for jazzmine_security-0.1.6-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6b551009ca6f3700cb56c422b4a5bd69f641452ae64b04baa91864f6378517ec
MD5 51e3a689f6e2cb0f17872382f987767d
BLAKE2b-256 d72756826fa259d573e43cd6bb379598ce2d6a0710e822a59b1b90ec8dda9029

See more details on using hashes here.

File details

Details for the file jazzmine_security-0.1.6-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for jazzmine_security-0.1.6-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b19ab9810b51f3aa12e506b0b4c73341d51e897d4d1a7be1bad9fc9ed1f7a419
MD5 f7ebfe5298fd1f960a2ab770c10c7247
BLAKE2b-256 a82d9d0889ec1bc1910b35bbd75092162c60151827b1ff40190337036c7dfb59

See more details on using hashes here.

File details

Details for the file jazzmine_security-0.1.6-cp38-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for jazzmine_security-0.1.6-cp38-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0af8bd31e99f70ee9b3147ec93c85e102e8b266d5e178914635c946165f28f94
MD5 3d38300eea456da3e52eb954b86f3482
BLAKE2b-256 8dfea0492efbd3fc23da0f7b645be62656049d8ea85ec73df3423e4481b714a8

See more details on using hashes here.

File details

Details for the file jazzmine_security-0.1.6-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jazzmine_security-0.1.6-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a82dfe92dfa0f638b832a73b1a6f331799afeb932d8efacd1fafbb848e1db478
MD5 ea21325e85c62b08129d0aa8a7138b96
BLAKE2b-256 71ab9d173256ed2c27bedd2063a11eb9ef8585d0f06f1f724c707528c6d63838

See more details on using hashes here.

File details

Details for the file jazzmine_security-0.1.6-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for jazzmine_security-0.1.6-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 569d662a2e5b4bdf16ad4f89bc21684ba1c2a18b71f2c1b5886f1a12762b587e
MD5 ad593b5a0bfafed5a93fcd3306980c39
BLAKE2b-256 c9ea43bce18ab62b94c96f0f67b8dbbfb7e07bd76f60a364fd7f8a1493516ff0

See more details on using hashes here.

File details

Details for the file jazzmine_security-0.1.6-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for jazzmine_security-0.1.6-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5c04d1d476f6df5c02b638d2ed5d62b19c081a2219243d1116947d6a5c56baa9
MD5 f8335e36c258ebb4963127a6d68c33fc
BLAKE2b-256 ba95ac28745df669d817ad56c4afc51739c20b24a0ca1e64bb51c27cf4732dbc

See more details on using hashes here.

File details

Details for the file jazzmine_security-0.1.6-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for jazzmine_security-0.1.6-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7928a62951f247782a82211f3fd00e16cce8790ca606b2cd75c580b68df8a0cb
MD5 8ea1b4a83835dee8981a01b23aacb318
BLAKE2b-256 7409ab7c5da8157444b48931701e4736fe5dbe6ff1ab868d69211ee098a1fb79

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