Python SDK for LittleData AI Risk & Governance Platform - Monitor, secure, and govern your AI applications
Project description
LittleData SDK
Python SDK for the LittleData AI Risk & Governance Platform - Monitor, secure, and govern your AI applications.
Features
- Real-time Monitoring: Track all AI/LLM interactions with <5ms latency overhead
- DLP Protection: Pre-flight content scanning to block or redact sensitive data
- Privacy Detection: Automatic PII detection in prompts and responses
- Multi-Provider Support: Works with OpenAI, Anthropic, Google, and more
- Async Batching: Non-blocking event recording with automatic batching
- Circuit Breaker: Built-in fault tolerance for production reliability
Installation
pip install littledata-sdk
For FastAPI/Starlette middleware support:
pip install littledata-sdk[middleware]
Quick Start
1. Get Your API Key
Sign up at littledata.ai to get your API key.
2. Initialize the Client
from ai_risk_sdk import AIRiskClient
# Initialize the client
client = AIRiskClient(
api_key="airisk_your_api_key_here",
endpoint="https://littledata.ai"
)
3. Record AI Events
import uuid
# Generate a trace ID for the interaction
trace_id = uuid.uuid4()
# Record a complete AI interaction
client.record_event(
event_type="llm_request",
trace_id=trace_id,
prompt="What is the capital of France?",
response="The capital of France is Paris.",
model_id="gpt-4",
model_provider="openai",
token_count_input=10,
token_count_output=8,
latency_ms=250,
)
# Don't forget to close the client when done
client.close()
Usage Patterns
Using as Context Manager
from ai_risk_sdk import AIRiskClient
with AIRiskClient(api_key="airisk_...", endpoint="https://littledata.ai") as client:
client.record_event(
event_type="llm_request",
prompt="Hello, world!",
response="Hello! How can I help you?",
model_id="claude-3-sonnet",
model_provider="anthropic",
)
# Client automatically flushes and closes
Using the Decorator
from ai_risk_sdk import AIRiskClient, track_ai_call
import openai
client = AIRiskClient(api_key="airisk_...", endpoint="https://littledata.ai")
@track_ai_call(client, model_id="gpt-4", model_provider="openai")
def generate_response(prompt: str) -> str:
response = openai.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}]
)
return response.choices[0].message.content
# The decorator automatically tracks the prompt, response, and latency
result = generate_response("Explain quantum computing in simple terms")
Async Support
from ai_risk_sdk import AIRiskClient, track_ai_call
import anthropic
client = AIRiskClient(api_key="airisk_...", endpoint="https://littledata.ai")
@track_ai_call(client, model_id="claude-3-sonnet", model_provider="anthropic")
async def generate_async(prompt: str) -> str:
client = anthropic.AsyncAnthropic()
message = await client.messages.create(
model="claude-3-sonnet-20240229",
messages=[{"role": "user", "content": prompt}]
)
return message.content[0].text
# Works seamlessly with async functions
result = await generate_async("What is machine learning?")
DLP Pre-flight Checks
Scan content for sensitive data before sending to an LLM:
from ai_risk_sdk import AIRiskClient
client = AIRiskClient(
api_key="airisk_...",
endpoint="https://littledata.ai",
enable_dlp=True,
)
# Check content before sending to LLM
user_input = "My SSN is 123-45-6789 and email is john@example.com"
dlp_result = client.evaluate_dlp_sync(content=user_input, direction="input")
if dlp_result["action"] == "block":
print(f"Blocked: Sensitive data detected")
elif dlp_result["action"] == "redact":
# Use the redacted content instead
safe_input = dlp_result["redacted_content"]
# Send safe_input to LLM
else:
# Content is safe to send
pass
FastAPI Middleware
from fastapi import FastAPI
from ai_risk_sdk.middleware import AIRiskMiddleware
app = FastAPI()
# Add middleware for automatic tracking
app.add_middleware(
AIRiskMiddleware,
api_key="airisk_...",
endpoint="https://littledata.ai",
)
@app.post("/chat")
async def chat(prompt: str):
# AI calls in this endpoint are automatically tracked
response = call_your_llm(prompt)
return {"response": response}
Configuration Options
from ai_risk_sdk import AIRiskClient
client = AIRiskClient(
# Required
api_key="airisk_...",
# API endpoint (default: https://littledata.ai)
endpoint="https://littledata.ai",
# Batching settings
batch_size=100, # Events per batch (default: 100)
flush_interval_ms=1000, # Flush interval in ms (default: 1000)
# Features
enable_dlp=True, # Enable DLP checks (default: True)
hash_prompts=False, # Hash prompts instead of sending full text (default: True)
# Reliability
timeout_ms=5000, # Request timeout (default: 5000)
circuit_breaker_threshold=5, # Failures before circuit opens (default: 5)
circuit_breaker_reset_ms=30000, # Circuit reset time (default: 30000)
)
Global Client
For convenience, you can use a global client instance:
import ai_risk_sdk
# Initialize once at startup
ai_risk_sdk.init(api_key="airisk_...", endpoint="https://littledata.ai")
# Use anywhere in your application
client = ai_risk_sdk.get_client()
client.record_event(...)
Event Types
The SDK supports various event types:
| Event Type | Description |
|---|---|
llm_request |
Complete LLM request/response pair |
prompt |
Standalone prompt event |
response |
Standalone response event |
error |
Error during AI operation |
API Reference
AIRiskClient
| Method | Description |
|---|---|
record_event() |
Record a generic AI event |
record_prompt() |
Record a prompt event |
record_response() |
Record a response event |
evaluate_dlp() |
Async DLP evaluation |
evaluate_dlp_sync() |
Sync DLP evaluation |
flush() |
Manually flush queued events |
close() |
Close client and flush remaining events |
track_ai_call Decorator
@track_ai_call(
client, # AIRiskClient instance
model_id="gpt-4", # Model identifier
model_provider="openai", # Provider name
capture_prompt=True, # Capture first argument as prompt
capture_response=True, # Capture return value as response
)
Dashboard
View your AI monitoring data at littledata.ai/dashboard:
- Real-time event stream
- DLP violation alerts
- Risk score trends
- Provider distribution
- Privacy findings
Support
- Documentation: littledata.ai/docs
- Issues: GitHub Issues
- Email: support@littledata.ai
License
MIT License - see LICENSE for details.
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 littledata_sdk-0.1.0.tar.gz.
File metadata
- Download URL: littledata_sdk-0.1.0.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d887ba093210621d49f409a34141412f6b3b553a8a1f2e532719fd75c0a77e6a
|
|
| MD5 |
dc52bcfbf84f15870db78bea54f0ad93
|
|
| BLAKE2b-256 |
fe1d28194dadc3334a36441500bee18e77716d05c6e5018b18c87afa3235ac13
|
File details
Details for the file littledata_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: littledata_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d644dbf09bbef6623887ce95e2993ff995e6e21c33ca308a5c1073047d360973
|
|
| MD5 |
2266d11ff2e8f344a249e8a23b9959dc
|
|
| BLAKE2b-256 |
373b6bb24cbef4e70833c34b00880b6aea9a5e02979280a16ef962bd66a27d67
|