Skip to main content

Aim Security Guardrails for OpenAI Agents

Project description

Aim Security Guardrails for OpenAI Agents

This package provides guardrails for OpenAI agents that integrate with the Aim Security API to detect and prevent harmful content, sensitive data leakage, prompt injections, and other security threats.

Installation

# install with pip
pip install aim-guardrails

# or install with poetry
poetry add aim-guardrails

Configuration

Set your Aim Security API key as an environment variable:

export AIM_API_KEY=<your-api-key>

Usage

You can use the helper functions to create guardrails with specific configurations:

from pydantic import BaseModel
from agents import Agent, Runner
from aim_guardrails import get_aim_input_guardrail, get_aim_output_guardrail

class MessageOutput(BaseModel):
    response: str

# Create guardrails with custom configuration
input_guardrail = get_aim_input_guardrail(
    api_key="your-custom-api-key",  # Optional: defaults to AIM_API_KEY env var
    api_base="https://your-custom-api-base.example.com",  # Optional
    user_email="user@example.com"  # Optional: for tracking
)

output_guardrail = get_aim_output_guardrail(
    api_key="your-custom-api-key",  # Optional: defaults to AIM_API_KEY env var
    api_base="https://your-custom-api-base.example.com",  # Optional
    user_email="user@example.com"  # Optional: for tracking
)

# Create an agent with the configured guardrails
agent = Agent(
    name="Customer support agent",
    instructions="You are a customer support agent. You help customers with their questions.",
    input_guardrails=[input_guardrail],
    output_guardrails=[output_guardrail],
    output_type=MessageOutput,
)

async def main():
    try:
        # This will be checked by the input guardrail
        result = await Runner.run(agent, "Hello, can you help me with my question?")
        print(f"Response: {result.final_output.response}")
    except InputGuardrailTripwireTriggered as e:
        print(f"Input guardrail triggered: {e}")
    except OutputGuardrailTripwireTriggered as e:
        print(f"Output guardrail triggered: {e}")

if __name__ == "__main__":
    import asyncio
    asyncio.run(main())

How It Works

  1. The input guardrail checks user messages before they're processed by the agent
  2. The output guardrail checks agent responses before they're returned to the user
  3. If restricted content is detected, a tripwire is triggered, raising an exception

Creating an Aim Security Guard

  1. Go to the Aim Application and create a new guard
  2. Configure your guard's policies in the prompt policy center
  3. Get your API key from the guard's page

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

aim_guardrails-0.1.2.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

aim_guardrails-0.1.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file aim_guardrails-0.1.2.tar.gz.

File metadata

  • Download URL: aim_guardrails-0.1.2.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.2 Darwin/24.3.0

File hashes

Hashes for aim_guardrails-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c4e99327f04d93a3d0b7479f11923e2fd94dda3d7e11cfa5dbe8fd8c28c95bba
MD5 dda2a5f124ce66d566b9cf7862d55eab
BLAKE2b-256 d2aadd90be85016311cfc457fce10a09ef2a21bf13f88f11d376ffff29fa118d

See more details on using hashes here.

File details

Details for the file aim_guardrails-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: aim_guardrails-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.2 Darwin/24.3.0

File hashes

Hashes for aim_guardrails-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 875f4565649517c922ed2b11be76cf7dea612f4795de6ff79bb3a1702b150f9a
MD5 430c33472cfa08134c570bf4961d5caf
BLAKE2b-256 6712003620ba53809b0fdc978f991170077576b63177619fd272a5287cdff881

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