API client for Tano Shield AI security services
Project description
Tano Shield
A Python client library for interacting with the Tano Shield AI security services.
Installation
pip install tano-shield
# or
poetry add tano-shield
Features
- AI Issue Detector: Protect your AI applications from harmful inputs and outputs
- PII Redaction: Detect and redact personally identifiable information
Usage
Quick Start
from tano_shield import TanoShield
# Initialize the client with your API key
tano_shield = TanoShield(api_key="your-api-key")
# Use the services
def example():
try:
# Check user input with the Issue Detector
firewall_result = tano_shield.firewall.check_input(
system_prompt="You are a helpful AI assistant",
user_input="Tell me about AI security",
response="I can provide information about AI security...",
event_id="conversation-12345",
security_checks=[
"sycophancy",
"faithfulness",
"harmfulness",
"implausible_output",
"information_disclosure",
"jailbreak"
]
)
print('Issue Detector check result:', firewall_result)
# Redact PII from text
pii_result = tano_shield.pii.redact_text(
text='My email is john.doe@example.com and my phone is 555-123-4567'
)
print('Redacted text:', pii_result['redacted_text'])
except Exception as error:
print('Error:', error)
example()
Using Individual Services
You can also use each service independently:
from tano_shield.firewall import FirewallClient
from tano_shield.pii import PIIClient
# Initialize just the Issue Detector client
firewall = FirewallClient(api_key="your-api-key")
# Check user input
result = firewall.check_input(
user_input='User message here',
system_prompt='You are a helpful assistant'
)
API Reference
TanoShield
The main client that provides access to all services.
tano_shield = TanoShield(
api_key="your-api-key",
base_url="https://api.example.com", # Optional
timeout=30, # Optional (default: 30)
version="v1" # Optional (default: 'v1')
)
Properties
firewall: FirewallClient instancepii: PIIClient instanceCREDIT_CONSTANTS: Credit cost constants
Methods
set_api_key(api_key): Update the API key for all services
FirewallClient (Issue Detector)
Client for the AI Issue Detector service.
Methods
check_input(**params): Check user input for security issuesparams['system_prompt']: The system prompt (optional)params['user_input']: The user input to check (required)params['response']: The AI response to check (optional)params['event_id']: A unique identifier for the event (optional)params['security_checks']: List of security checks to perform (optional)
get_settings(): Get Issue Detector settingsupdate_settings(settings): Update Issue Detector settingsget_history(**options): Get Issue Detector call historyget_analytics(**options): Get Issue Detector analytics
PIIClient
Client for the PII Redaction service.
Methods
redact_text(text, entity_types=None, mask_mode=False): Redact PII from textdetect_pii(text, entity_types=None): Detect PII in text without redactingget_supported_entity_types(): Get supported PII entity types
Credit System
Tano Shield uses a credit system for API usage. Each API call consumes credits based on the service used.
from tano_shield import CREDIT_CONSTANTS
print(CREDIT_CONSTANTS.FREE_CREDITS_PER_MONTH) # 1000
print(CREDIT_CONSTANTS.FIREWALL_CHECK_COST) # 1
print(CREDIT_CONSTANTS.PII_REDACTION_COST) # 1
Error Handling
The library provides custom error classes for different types of errors:
from tano_shield.core.errors import (
TanoShieldError,
AuthenticationError,
ApiRequestError
)
try:
tano_shield.firewall.check_input(user_input='test')
except AuthenticationError as error:
print('Authentication failed:', error)
except ApiRequestError as error:
print('API request failed:', error, error.status)
except TanoShieldError as error:
print('Tano Shield error:', error, error.code)
except Exception as error:
print('Unknown error:', error)
Example API Call
Here's an example of how to use the Issue Detector with requests:
import requests
import json
url = "https://api.tanolabs.com/api/v1/firewall-check"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
}
data = {
"prompt": "Tell me about AI security",
"system_prompt": "You are a helpful AI assistant",
"user_input": "Tell me about AI security",
"response": "I can provide information about AI security...",
"event_id": "conversation-12345",
"securityChecks": ["sycophancy", "faithfulness", "harmfulness", "implausible_output", "information_disclosure", "jailbreak"]
}
response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.json())
Building and Publishing
Local Development
To build and install the package locally:
# Navigate to the package directory
cd tano-shield-py
# Run the build and install script
./build_and_install.sh
Publishing to PyPI
To publish the package to PyPI:
- Update the version number in
setup.pyandpyproject.toml - Run the publish script:
./publish_to_pypi.sh
- Follow the prompts to publish to TestPyPI or PyPI
For detailed instructions, see PUBLISHING.md.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tano_shield-0.1.0.tar.gz.
File metadata
- Download URL: tano_shield-0.1.0.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9c28151dc85440592d15397adc0bd25d073980519b9c88905ce9f4c282ed9a8
|
|
| MD5 |
08e53886447ff883602110a0cdb484fe
|
|
| BLAKE2b-256 |
19bbd090e48d8079520c9e89edc9009d11e8d0896b3e6ca190ab20b055c3474d
|
File details
Details for the file tano_shield-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tano_shield-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7961229008c03abb3d3148d982588657714037ef25cdc9c6b4e2e14e3ac398c
|
|
| MD5 |
651a547cd08b82539ea5390c8f288b67
|
|
| BLAKE2b-256 |
a990104a7715d8bdd9501916a3660ae165645d5ab4141b5a396d58382a49e6dd
|