Skip to main content

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"],
        ))

        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

MIT

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

lakera_red_sdk-0.1.0.tar.gz (44.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lakera_red_sdk-0.1.0-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file lakera_red_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: lakera_red_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 44.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for lakera_red_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f0c2d5de1281c0e01aea05a656eb9b1d884958ec274de5737fd84d811ad6ffee
MD5 fe44c90c0b45b0435b4806879520a687
BLAKE2b-256 fd8b527cbd4b76ad9c0bd68542f6de4f43e28b28b57878b07992056dd52cac1f

See more details on using hashes here.

File details

Details for the file lakera_red_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lakera_red_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for lakera_red_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9c8131f0cfc1244f5580bf920aa182e1205acdf4fa3351bdca1a18490254d1dc
MD5 4ccc1af22de67bdbe884d1aa8fea0710
BLAKE2b-256 4f9ba2e0e54d7c0be0981a94812efcfc38dfaa689c5c6cceb9c27a971c289426

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page