Skip to main content

Python SDK for AI Guardrails - Simple API for invoking and managing guardrails

Project description

General Analysis SDK

Python SDK for General Analysis AI Guardrails.

Installation

pip install generalanalysis

Quick Start

import generalanalysis

# Uses GA_API_KEY env var by default
client = generalanalysis.Client()

# Check text against guard policies
result = client.guards.invoke(guard_id=1, text="Text to check")

if result.block:
    print("Blocked:", [p.name for p in result.policies if not p.passed])

Configuration

# API key priority: parameter > GA_API_KEY env var
client = generalanalysis.Client(api_key="your-key")

# Custom endpoint (default: https://redit-api-dev.generalanalysis.com)
client = generalanalysis.Client(base_url="http://localhost:5001")

# Resource cleanup
with generalanalysis.Client() as client:
    guards = client.guards.list()

API Reference

Guards Operations

# List guards
guards = client.guards.list()

# Get guard details  
guard = client.guards.get(guard_id=1)

# Invoke guard
result = client.guards.invoke(guard_id=1, text="...")
print(f"Blocked: {result.block}, Latency: {result.latency_ms}ms")

# Generate policies from job
policies = client.guards.generate_policies_from_job(job_id=123)

# Get logs (paginated)
logs = client.guards.list_logs(guard_id=1, page=1, page_size=50)

Async Support

import asyncio
import generalanalysis

async def main():
    async with generalanalysis.AsyncClient() as client:
        results = await asyncio.gather(*[
            client.guards.invoke(guard_id=1, text=t) 
            for t in texts
        ])

Error Handling

from generalanalysis import AuthenticationError, GuardNotFoundError

try:
    result = client.guards.invoke(guard_id=999, text="test")
except GuardNotFoundError:
    print("Guard not found")
except AuthenticationError:
    print("Invalid API key")

Type Hints

Fully typed for IDE support:

from generalanalysis import Client, Guard, GuardInvokeResult

def check_safety(client: Client, text: str) -> bool:
    result: GuardInvokeResult = client.guards.invoke(guard_id=1, text=text)
    return not result.block

License

MIT

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

generalanalysis-0.2.0.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

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

generalanalysis-0.2.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file generalanalysis-0.2.0.tar.gz.

File metadata

  • Download URL: generalanalysis-0.2.0.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for generalanalysis-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0eeb533ad3b9497ed6810387a85c70f70be474fdf59917c9855d61b8d415370a
MD5 1f94ef8b5dcf223b8836ac5e91ff6515
BLAKE2b-256 e297ab60d434a19952fc477de11b0c09d2d8f6e3b8e9c4bc4560faff1675a0ab

See more details on using hashes here.

File details

Details for the file generalanalysis-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for generalanalysis-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f921080212ab41f3de51d3f450744728787b1dfc317eacb23fe86ed686f07a21
MD5 fe32e11bbac22fbbebde1e4a0e1c165f
BLAKE2b-256 1692d50aad1488abc48f59125053874bb1a5b365feb5d2a322d24a44d8906251

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