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.

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 harmful 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.1.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.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aim_guardrails-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 c5dc5a25c419303d05af7cd668aa2b2d620b3a15340e16f89b75598d6d9808a0
MD5 84856a0f130a0a5a6bba8529f34dd312
BLAKE2b-256 b01c39e2a1e1992069bd0a16cf0cd77d77648f5753ff09d01ef7a965f41242e6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aim_guardrails-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cd5374118883d3be40eb5087a695b8a1a6dc16ef5e20571600b8a9a6a9d2b65d
MD5 ad957d144a187ff5a2b8200d8e865ad4
BLAKE2b-256 73dced9c4c9b125e2a95cef97225aea5a9ba93e057714fba5ae05900cc6df173

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