Reference
Complete reference for the lakera-red-sdk package.
TypeScript
Python
Requires Node.js 22+. Install with npm install lakera-red-sdk.
LakeraRedClient
The main entry point. Creates targets and initiates scans.
TypeScript
Python
Constructor Options
TypeScript
Python
Creating a Target
Finds or creates a target by name and ensures it has a recon profile. Returns a Target
instance. The profile lives on the target and is reused by every scan, so you create a
target once before scanning.
There are three outcomes, depending on what you pass:
- With
appContext(orappContextFile): the profile is set directly and no recon runs — a handler is not needed. - Without app context, when the target has no profile yet: recon runs by relaying prompts through the handler (relay targets have no URL to probe directly), so the handler is required — omitting it throws.
- Without app context, when the target already has a profile (from a prior run or the dashboard): the existing profile is reused and no recon runs.
You can also attach ground truth — the target’s real system prompt
and/or tool definitions — via groundTruth. Like the recon profile, it lives on the
target and is reused across scans; the judge uses it to evaluate attacks more precisely.
TypeScript
Python
The first argument is an options object; the optional second argument is a session handler, used only when recon needs to run.
Returns a Target.
Fetching a Target
Fetches an existing target by its id. Read-only: unlike createOrGetTarget /
create_or_get_target, it never creates a target or runs recon. Use it to reuse a
target created earlier (for example in the dashboard or a previous run) before creating
a scan. Throws if no target with that id exists or the caller cannot access it.
There are two ways to get a target’s id:
- Read
target.targetIdfrom theTargetreturned bycreateOrGetTargetand store it for later use. - Open the target in the dashboard and copy the id from the URL:
/targets/<targetId>.
TypeScript
Python
Updating a Target
Updates an existing target’s name, recon profile and/or ground truth. When provided,
appContext and groundTruth each replace the target’s stored value wholesale (each is
always a complete payload, matching createOrGetTarget). At least one of name,
appContext or groundTruth must be supplied. Returns a fresh Target reflecting the
updated state. Throws if no target with that id exists or the caller cannot access it.
TypeScript
Python
Running Recon
Re-runs recon on an existing target and returns the freshly-generated recon profile. Relays the recon prompts through the handler (relay targets have no URL to probe directly) and persists the result on the target. Use it when the underlying agent has changed and its profile needs updating.
The server persists the result by sanitizing then merging onto the stored profile, so
what it keeps can differ from this run’s raw output — a total failure is a no-op that
leaves the existing profile in place. This method returns only what this run produced,
or undefined/None when it yielded nothing usable; call getTarget for the persisted
target state. Throws if no target with that id exists or the caller cannot access it.
TypeScript
Python
Target
A handle to a relay target. Returned by createOrGetTarget, getTarget, and
updateTarget; pass its targetId to createScan. It carries the target’s current
recon profile as recon and its ground truth as groundTruth, or undefined/None
when the target has none. hasRecon is a convenience getter derived from recon.
TypeScript
Python
See ReconContext for the recon fields and GroundTruth
for the ground truth fields. Reading groundTruth back returns tools as a list with
one entry per line of the stored value.
Creating a Scan
Creates a scan against a target. Returns a Scan instance. The scan does not begin
execution until scan.run() is called. The recon profile is read from the target — set
it up first with createOrGetTarget and pass its targetId.
TypeScript
Python
ReconContext
Describes your application so Red can tailor attacks to its capabilities and restrictions.
TypeScript
Python
YAML file (app-context.yaml):
TypeScript
Python
GroundTruth
The target’s real system prompt and/or tool definitions. The judge uses this ground truth to evaluate attacks more precisely — for example, to confirm a leaked system prompt or an out-of-policy tool call rather than inferring it — which reduces false positives.
Ground truth is attached to the target (via createOrGetTarget or
updateTarget), persisted on it, and reused across every scan. At
least one field must be provided; both are optional, so supply whichever you have.
tools is a list of strings — one entry per tool, commonly each tool’s JSON schema, but
any textual description of a tool works. The entries are joined into a single string
when stored, so reading the target back returns one entry per line.
TypeScript
Python
Ground truth can also be carried in the appContextFile YAML via its
systemPrompt / tools keys, so a single file fully describes a target. When both the
file and an inline groundTruth / ground_truth are supplied, the inline value wins.
CustomObjective
Defines a custom attack objective inline. Custom objectives are passed directly in the scan request and never persisted to the objectives catalog.
TypeScript
Python
Custom objectives can be combined with standard objectives. Keys must not overlap with
any IDs in objectives.
Scan
Manages scan execution and result retrieval.
Properties
TypeScript
Python
The dashboardLink property returns the URL to the scan’s page on the Lakera Red
dashboard. The server automatically redirects to the progress view while the scan is
still running. Available immediately after creating the scan.
Run
Executes the scan. Polls the server for attack messages and invokes your handler for each concurrent session. Returns when the scan completes or times out.
TypeScript
Python
Use the finally block to release agent resources (connections, memory) once a session
ends. This is especially important for crescendo sessions that maintain
state across multiple turns.
Behavior:
- Recon runs at target creation, not here — by the time
run()starts, the target already has its profile, so your handler only receives attack sessions. - Manages concurrent sessions up to the configured
concurrencylimit - Retries on network errors with exponential backoff (1s–5s)
- Stops automatically after 3 minutes of inactivity (no messages from server)
- If your handler throws/raises before calling
respond(), the SDK submits an error to the server on your behalf
Get Results
Retrieves evaluated scan results.
TypeScript
Python
Returns a ScanResults object:
Get Dashboard Link
Returns the URL to the scan’s report page on the Lakera Red dashboard. The server automatically redirects to the progress view while the scan is still running.
TypeScript
Python
Write Results
Writes results to a JSON file and returns the resolved absolute path.
TypeScript
Python
Session
Passed to your scan.run() handler. An async iterable that yields attack messages.
TypeScript
Python
SessionMessage
TypeScript
Python
ScanResultEntry
Each entry in the results array:
TypeScript
Python
Evaluation
Logging
The SDK outputs structured JSON logs to stderr by default, keeping stdout clean for your application output.
Configuration
Control log verbosity via the logLevel constructor parameter or the
LAKERA_RED_LOG_LEVEL environment variable:
Custom Logger
Provide your own logger to integrate with your existing observability stack:
TypeScript
Python
Logger Utilities
TypeScript
Python
Examples Helper
TypeScript
Python
Installing lakera-red-sdk also installs a lakera-red-sdk command for bootstrapping
example projects.
The bundled examples are pinned to the installed SDK version, so they always match the package you’re using.
Strategies
The strategy controls how the SDK generates adversarial prompts.
TypeScript
Python
Static
Sends a fixed set of adversarial prompts per objective. Each prompt is independent — there is no conversational escalation between turns. This makes static scans fast, deterministic, and well-suited for CI gates where you want quick, reproducible results.
TypeScript
Python
Crescendo
A multi-turn strategy where the attacker gradually escalates over several conversational turns within a single session. Crescendo better simulates real-world persistent attackers and tests whether your agent can maintain its guardrails under sustained conversational pressure.
TypeScript
Python
Smoke
Server-defined canned probes for a quick sanity check. Objectives are ignored — the server uses its own fixed probe set.
TypeScript
Python
Choosing a Strategy
Choose static for fast regression checks and crescendo for deeper adversarial
evaluation during pre-release security reviews.
Objective IDs
Pass these IDs in the objectives array/list when creating a scan. If you omit
objectives, all objectives across all categories are included (except when using the
smoke strategy, which uses its own fixed probe set).
You can also define your own objectives using customObjectives (TypeScript) or
custom_objectives (Python). See CustomObjective.
Security
Safety
Responsible
For detailed descriptions of what each objective tests, see Attack Coverage.