Skip to main content

Safety/alignment guardrails for AI agents

Project description

🛡️ Bumpers

Add safety guardrails to your AI agents with just a few lines of code. Bumpers is a Python library that helps you build safer AI applications by validating agent actions and outputs in real-time.

Python Version License Build Status

✨ Features

  • 🔒 Validation Engine: Pre-built validators for common safety checks
  • 🤖 Framework Support: Works with both custom agents and popular frameworks like LangChain
  • 🚫 Action Control: Whitelist allowed actions and block dangerous operations
  • 🔍 Content Filtering: Detect and block sensitive or inappropriate content
  • 📊 Semantic Monitoring: Track semantic drift and goal fulfillment
  • ⏱️ Rate Limiting: Prevent infinite loops and resource abuse
  • 📝 Logging & Analytics: Track and analyze agent behavior

🚀 Quick Start

Installation

  1. Install:
pip install bumpers

Basic Usage with LangChain

from langchain.agents import AgentExecutor
from bumpers.core.engine import CoreValidationEngine
from bumpers.validators.action import ActionWhitelistValidator
from bumpers.validators.content import ContentFilterValidator
from bumpers.integrations.langchain_callback import BumpersLangChainCallback

# Set up validation engine
validation_engine = CoreValidationEngine()

# Add validators
validation_engine.register_validator(
    ActionWhitelistValidator(allowed_actions=["search", "calculate"]),
    ValidationPoint.PRE_ACTION
)
validation_engine.register_validator(
    ContentFilterValidator(forbidden_words=["confidential", "secret"]),
    ValidationPoint.PRE_OUTPUT
)

# Create Bumpers callback
bumpers_callback = BumpersLangChainCallback(validation_engine=validation_engine)

# Add to your LangChain agent
agent_executor = AgentExecutor(
    agent=agent,
    tools=tools,
    callbacks=[bumpers_callback]  # Add Bumpers protection
)

# Use normally - Bumpers will automatically protect your agent
result = agent_executor.invoke({"input": "What's 2 + 2?"})

🛡️ Available Validators

Action Control

  • ActionWhitelistValidator: Restrict which actions an agent can perform
  • ResourceValidator: Prevent resource-intensive operations
  • RateLimitValidator: Control action frequency

Content Safety

  • ContentFilterValidator: Block sensitive or inappropriate content
  • LLMSafetyValidator: Use LLMs to validate content safety
  • PatternValidator: Block content matching specific patterns

Semantic Control

  • SemanticDriftValidator: Keep responses on topic
  • GoalFulfillmentValidator: Ensure answers address the original question
  • TemporalRelevanceValidator: Validate time-based responses

Chain Control

  • ChainLengthValidator: Limit action chain length
  • RedundancyLoopingValidator: Detect and prevent action loops

🔍 Monitoring & Analytics

Track agent behavior and get alerts:

from bumpers.monitoring.monitor import BumpersMonitor
from bumpers.monitoring.conditions import create_high_failure_rate_condition

def alert_handler(message):
    print(f"🚨 Alert: {message}")

# Create monitor
monitor = BumpersMonitor(
    logger=logger,
    alert_handlers=[alert_handler]
)

# Add conditions
monitor.add_condition(
    create_high_failure_rate_condition(threshold=0.3)
)

# Start monitoring
monitor.start()

📊 Analytics

Analyze agent behavior:

from bumpers.analytics.analyzer import BumpersAnalyzer

analyzer = BumpersAnalyzer(logger)

# Get validation statistics
stats = analyzer.get_validation_stats()
print("Validation Stats:", stats)

# Get intervention summary
summary = analyzer.get_intervention_summary()
print("Interventions:", summary)

🎯 Fail Strategies

Customize how validators handle failures:

from bumpers.validators.base import FailStrategy

validator = ContentFilterValidator(
    forbidden_words=["confidential"],
    fail_strategy=FailStrategy.STOP  # Immediately halt execution
)

validator = RateLimitValidator(
    max_actions_per_minute=10,
    fail_strategy=FailStrategy.RAISE_ERROR  # Raise exception but allow catching
)

validator = PatternValidator(
    patterns=[r"sensitive\s+data"],
    fail_strategy=FailStrategy.LOG_ONLY  # Just log the violation
)

🔧 Custom Validators

Create your own validators:

from bumpers.validators.base import BaseValidator
from bumpers.core.engine import ValidationResult, ValidationPoint

class CustomValidator(BaseValidator):
    def __init__(self, name: str = "custom"):
        super().__init__(name)

    def validate(self, context: dict) -> ValidationResult:
        # Implement your validation logic
        return ValidationResult(
            passed=True,
            message="Validation passed",
            validator_name=self.name,
            validation_point=ValidationPoint.PRE_ACTION,
            context=context
        )

🌟 Star History

Star History Chart

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

bumpers-0.1.3.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

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

bumpers-0.1.3-py3-none-any.whl (27.9 kB view details)

Uploaded Python 3

File details

Details for the file bumpers-0.1.3.tar.gz.

File metadata

  • Download URL: bumpers-0.1.3.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.4

File hashes

Hashes for bumpers-0.1.3.tar.gz
Algorithm Hash digest
SHA256 ea5d5f16bd0258720643bd9ba254c64f290e5060ef19ba317444bb224498fe54
MD5 b39e1abf74d89478e383533d315e4805
BLAKE2b-256 f4ce1a4351681f968f38bb35ce9122bf848c68462325be00c338088f4b641deb

See more details on using hashes here.

File details

Details for the file bumpers-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: bumpers-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 27.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.4

File hashes

Hashes for bumpers-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 599704fda3d15e2ce7c9e2612a45434715f1b7afa3e6ff593d8ba9ae9d39fcc0
MD5 5d434cc7328a871dccd1453b1c822653
BLAKE2b-256 14adc3e7d30967dec1a9627807980df4196c9dc55543d1fca02cd80e40f67ce1

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