ShieldAI Liftoff in Minutes! ⏱️
🚀 ShieldAI Quick Start: Your First Protected AI Call!
Ready to add a powerful security layer to your AI model? This guide gets you up and running FAST. Let's go! ✨
📋 Pre-flight Checklist (What You Need):
✅ A ShieldAI Account
🔑 Your unique ShieldAI API Key .
🎯 An accessible endpoint URL for the AI model you want to protect
🐍 Basic knowledge of Python .
Mission Steps: 🧑🚀
Step 1: Install the ShieldAI Python SDK 📦
Open your terminal or command prompt and install our handy Python SDK using pip:
pip install shieldai-sdk
This command downloads and installs the necessary library to interact with the ShieldAI platform from your Python code.
💡 **Tip:** Using a virtual environment (`venv`, `conda`) is highly recommended to keep project dependencies organized!
Step 2: Initialize ShieldAI in Your Code ✨
In your Python script (e.g., `app.py`, `main.py`), import the library and initialize it with your API key. This establishes the connection to our platform.
# Import the library import shieldai import os # Recommended way to handle secrets # Initialize ShieldAI (Best practice: use environment variables for API keys!) api_key = os.getenv("SHIELDAI_API_KEY", "YOUR_FALLBACK_API_KEY") # Replace with your actual key if not using env vars if not api_key or api_key == "YOUR_FALLBACK_API_KEY": print("⚠️ WARNING: ShieldAI API Key not found or using fallback!") shieldai.init(api_key=api_key) print("ShieldAI SDK Initialized!")
🔒 **Security Best Practice:** Avoid hardcoding API keys directly in your source code. Use environment variables or a secrets management system.
Step 3: Configure Your Protection Policy ⚙️
Define how ShieldAI should protect your model. For this quick start, we'll use a default policy and specify your model's endpoint.
# Define the protection configuration - protection_config = { "policy_id": "default-balanced-security", "target_uri": "YOUR_MODEL_ENDPOINT_URL", "request_structure": { # Help ShieldAI understand your request format "prompt_field": "user_prompt" "response_structure": { "output_field": "model_response" print("Protection Configuration Defined:", protection_config)
🔧 **Customization:** Explore your ShieldAI dashboard to see available `policy_id` options or learn how to create custom policies later!
Step 4: Make a Protected AI Call 🛡️➡️🤖
Instead of calling your model directly, route the request through ShieldAI's `protect()` method. ShieldAI analyzes it, and if safe, forwards it to your `target_uri`.
user_input = "Tell me about the history of artificial intelligence." request_payload = {"user_prompt": user_input} print(f"\nAttempting to protect and call model with input: '{user_input}'") try: protection_result = shieldai.protect( config=protection_config, request_data=request_payload ) # Check the outcome if protection_result.is_safe: print("\n✅ Request deemed SAFE by ShieldAI.") print("✅ ShieldAI forwarded request to:", protection_config['target_uri']) print("✅ Model Response (processed by ShieldAI):") # The actual response from your model is nested within the result print(protection_result.response_data) else: # Request was blocked! print(f"\n❌ Request BLOCKED by ShieldAI!") print(f" Reason: {protection_result.block_reason}") print(f" Detected Threats: {protection_result.threats_detected}") # Do NOT proceed to call your model directly here except shieldai.ShieldAIError as e: # Handle potential errors during the protection call (e.g., network issues, config errors) print(f"\n💥 An error occurred during ShieldAI protection: {e}") except Exception as e: # Handle other potential errors in your code print(f"\n💥 An unexpected error occurred: {e}")
Step 5: Observe in Your Dashboard 👀
Log in to your ShieldAI Dashboard. Navigate to the 'Events' or 'Monitoring' section. You should see an entry corresponding to the API call you just made, indicating whether it was allowed or blocked, and why!
🎉 Congratulations! Mission Accomplished! 🎉
You've successfully integrated ShieldAI and made your first protected AI call! Your model is now safer from basic threats.
Next Steps:
Explore different Policies in your dashboard.
Integrate ShieldAI into your actual application logic.
Dive deeper into the Platform Features!
Last updated