Official Python SDK for Lakera Red — run adversarial scans against your AI agents and chatbots.
Project description
Lakera Red SDK
Official Python SDK for Lakera Red — run adversarial scans against your AI agents from your own runtime.
Lakera is a Check Point company.
Install
pip install lakera-red-sdk
Quick start
import asyncio
from lakera_red_sdk import LakeraRedClient, LakeraRedClientOptions, CreateScanOptions, Session
async def main():
async with LakeraRedClient(LakeraRedClientOptions(
api_key="sk_lr_...",
base_url="https://red-webhooks.lakera.ai",
log_level="info",
)) as client:
scan = await client.create_scan(CreateScanOptions(
target="My Agent",
name="Example scan",
concurrency=1,
objectives=["safety.hate-speech.1"],
language="fr", # optional; defaults to "en"
))
async def handler(session: Session) -> None:
async for message in session:
reply = await your_agent(session.id, message.attack)
await message.respond(reply)
await scan.run(handler)
await scan.write_results("./results.json")
asyncio.run(main())
Key concepts
| Concept | Description |
|---|---|
| Target | A named configuration representing the system under test. Created once, reused across scans. |
| Session | A multi-turn conversation. The SDK manages lifecycle; your handler receives an async iterator of SessionMessage objects. |
| Strategy | static = independent single-turn probes (fast). crescendo = adaptive multi-turn attacks. smoke = canned probe set. |
| Concurrency | How many sessions run in parallel. For crescendo, automatically capped to the number of objectives. |
Multi-turn sessions with cleanup
For stateful agents that accumulate per-session state (conversation history, DB
connections, etc.), use try/finally to clean up:
async def handler(session: Session) -> None:
try:
async for message in session:
reply = await chatbot(session.id, message.attack)
await message.respond(reply)
finally:
clear_session(session.id)
Configuration
from lakera_red_sdk import LakeraRedClient, LakeraRedClientOptions
async with LakeraRedClient(LakeraRedClientOptions(
api_key="sk_lr_...", # Lakera Red API key
base_url="https://red-webhooks.lakera.ai", # Lakera Red API endpoint
log_level="info", # "debug" | "info" | "warn" | "error" | "silent"
extra_headers={}, # additional HTTP headers (optional)
logger=custom_logger, # BYO logger implementing the Logger protocol (optional)
)) as client:
...
Examples
| Example | What it demonstrates |
|---|---|
| echo | Simplest integration — echoes attacks back |
| chatbot | Stateful multi-turn chatbot with Claude + session cleanup |
License
Development
pip install -e ".[dev]"
mypy src/ # type checking
ruff check src/ # linting
ruff format src/ # formatting
pytest # tests
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
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 lakera_red_sdk-0.2.0.tar.gz.
File metadata
- Download URL: lakera_red_sdk-0.2.0.tar.gz
- Upload date:
- Size: 45.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ea0a821597e872279e258e7bd5e017ac2ab04250bdcd3f3b0da56e268e8172d
|
|
| MD5 |
060befb338cadee82954ebdef6cd2f6f
|
|
| BLAKE2b-256 |
2cd2ba7874a7e5e13e9a2f9e19985de122f9ac79dd232ed8e017353bcf37841e
|
File details
Details for the file lakera_red_sdk-0.2.0-py3-none-any.whl.
File metadata
- Download URL: lakera_red_sdk-0.2.0-py3-none-any.whl
- Upload date:
- Size: 20.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0000fce378348d62eeea4c8d43fdb00d41c913e033001161d336bb95a6b6739f
|
|
| MD5 |
9a6550ac59cf40dadd8300290335dcf9
|
|
| BLAKE2b-256 |
a82ec1e36356c05b91682c255e7bc5d4ef236cf38c5a42131ac7a3bf3eedd810
|