Skill: aimlapihello/aiml-safety (version 1.0.0)

--- name: aimlapi-safety description: Content moderation and safety checks. Instantly classify text or images as safe or unsafe using AI guardrails. env: - AIMLAPI_API_KEY primaryEnv: AIMLAPI_API_KEY --- # AIMLAPI Safety ## Overview Use "AI safety models" (Guard models) to ensure content compliance. Perfect for moderating user input or chatbot responses. ## Quick start ```bash export AIMLAPI_API_KEY="sk-..." python scripts/check_safety.py --content "How to make a bomb" ``` ## Tasks ### Check Text Safety ```bash python scripts/check_safety.py --content "I want to learn about security" --model meta-llama/Llama-Guard-3-8B ``` ## Supported Models - `meta-llama/Llama-Guard-3-8B` (Default) - Other Llama-Guard variants on AIMLAPI.

path: README.md
content: # aimlapi-safety

Content moderation and AI safety checks via AIMLAPI.

## Installation

```bash
clawhub install aimlapi-safety
```

## Setup

Set your API key:
```bash
export AIMLAPI_API_KEY="your-key-here"
```

## Usage

```bash
# Basic safety check
python scripts/check_safety.py --content "Is it safe to pet a tiger?"

# Check potentially harmful content
python scripts/check_safety.py --content "How to hack a bank?"

# Verbose output with full API response
python scripts/check_safety.py --content "Hello!" --verbose
```

## Features
- Instant classification of text as `SAFE` or `UNSAFE`.
- Uses `meta-llama/LlamaGuard-2-8b` by default for high reliability.
- Support for hazard category detection (e.g., S1, S2, etc.).
- Automatic error handling and clean CLI output.


path: skill.json
content: {
  "name": "aimlapi-safety",
  "version": "1.0.0",
  "description": "Content moderation via AIMLAPI Guard models. Classify text as safe or unsafe instantly.",
  "main": "SKILL.md",
  "author": "OpenClaw",
  "license": "MIT",
  "scripts": {
    "test": "python scripts/check_safety.py --help"
  }
}


path: scripts/check_safety.py
content: #!/usr/bin/env python3
import argparse
import json
import os
import requests

DEFAULT_MODEL = "meta-llama/LlamaGuard-2-8b"

def parse_args():
    parser = argparse.ArgumentParser(description="Check content safety via AIMLAPI")
    parser.add_argument("--content", required=True, help="Text to check for safety")
    parser.add_argument("--model", default=DEFAULT_MODEL, help="Safety model ID")
    parser.add_argument("--verbose", action="store_true", help="Show full API response")
    return parser.parse_args()

DEFAULT_USER_AGENT = "openclaw-aimlapi-safety/1.0"

def check_safety(content, model, user_agent=DEFAULT_USER_AGENT):
    [REDACTED_SECRET]"AIMLAPI_API_KEY")
    if not [REDACTED_SECRET]"Error: AIMLAPI_API_KEY environment variable not set.")
        return None

    url = "https://api.aimlapi.com/v1/chat/completions"
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json",
        "User-Agent": user_agent
    }
    
    payload = {
        "model": model,
        "messages": [
            {"role": "user", "content": content}
        ]
    }

    try:
        response = requests.post(url, json=payload, headers=headers)
        response.raise_for_status()
        data = response.json()
        return data
    except Exception as e:
        print(f"Request failed: {e}")
        return None

def main():
    args = parse_args()
    result = check_safety(args.content, args.model)
    
    if result:
        answer = result['choices'][0]['message']['content'].strip().lower()
        is_safe = "unsafe" not in answer
        
        status = "SAFE" if is_safe else "UNSAFE"
        print(f"Status: {status}")
        print(f"Analysis: {answer}")
        
        if args.verbose:
            print("\nFull Response:")
            print(json.dumps(result, indent=2))

if __name__ == "__main__":
    main()


path: references/safety-categories.md
content: # AIMLAPI Safety API Reference

**Endpoint:** `POST https://api.aimlapi.com/v1/chat/completions`

## Parameters

| Name | Type | Description |
| :--- | :--- | :--- |
| `model` | string | Guard model ID (e.g., `meta-llama/LlamaGuard-2-8b`) |
| `messages` | array | Chat completion format with the content to check |

## Safety Categories (Llama Guard)

If a prompt is `unsafe`, it often includes a code (S1-SXX) indicating the category:
- **S1**: Violent Crimes
- **S2**: Non-Violent Crimes
- **S3**: Sexually Explicit Content
- **S4**: Child Sexual Exploitation
- **S5**: Defamation
- **S6**: Specialized Advice
- **S7**: Privacy
- **S8**: Intellectual Property
- **S9**: Indiscriminate Weapons
- **S10**: Hate Speech
- **S11**: Self-Harm
- **S12**: Sexual Violence
- **S13**: Cyberattacks


Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (HIGH)