Adapter SDK Reference
Focus
Focus
Prisma AIRS

Adapter SDK Reference

Table of Contents

Adapter SDK Reference

The SDK reference for a custom target adapter: the functions you implement, what the platform passes in, and what you return.
Where Can I Use This?What Do I Need?
  • Prisma AIRS (AI Red Teaming)

Function Patterns

Implement one of two request patterns. You may add the optional authenticate() and session_pre_process() hooks to either pattern.
  • Pattern A—pre_process and post_process
    You build the request, and the platform makes the HTTP call and passes the response to your post_process() function. Use this pattern for standard HTTP targets, including those that require multiple HTTP calls. Use context.http inside pre_process() for additional per-turn calls. Use session_pre_process() for one-time setup.
  • Pattern B—call_target
    You make the call(s) yourself and return the reply. Use this when the target is not plain request/response HTTP: WebSocket, GraphQL, SDK-based clients, or custom framing and streaming protocols.
If you define both patterns in the same script, call_target takes precedence and pre_process or post_process are not called. Either pattern can add the optional authenticate() and session_pre_process() hooks.
FunctionPatternRequired?Purpose
pre_process(context, inference_input)AYes (Pattern A)Build the HTTP request to send to your target.
post_process(context, raw_response)AYes (Pattern A)Extract the reply from the target's HTTP response.
call_target(context, inference_input)BYes (Pattern B)Make the call(s) yourself and return the reply.
authenticate(context)EitherNoObtain and cache authentication credentials; refreshed automatically by the platform.
session_pre_process(context)EitherNoOne-time setup on the first turn of every conversation.
The following names are available in your script without importing:
InferenceInput, PreProcessResult, PostProcessResult, CallTargetResult, AuthResult, SessionPreProcessResult, RawResponse AudioFormat, FileMimeType, ModalityInput, Data, FormatItems raise_rate_limited(), raise_auth_error(), raise_target_error(), raise_content_filtered()
For all other dependencies, use the Python standard library and the bundled HTTP client. See Available Packages.

Version Requirements

The base adapter feature works with every client from v1.4.0. Some features need a newer Network Channel client, because the adapter runner ships inside the client.
FeatureMinimum client
Custom target adapters (all functions, context, text input)v1.4.0
Google Vertex AI libraries in the adapter runnerv1.4.4
Audio and document attacks, and audio repliesv1.5.0
inference_input.audio and inference_input.file (see Input Parameters)v1.9.0
On a client older than v1.9.0, audio and documents still arrive, in the deprecated audio_b64, file_b64, and related fields.

Conventions

Follow these conventions to avoid common adapter errors.
  • Return the declared result type.
    If your function returns a raw Python string or a raw dictionary directly, instead of wrapping the value in the required result type (for example, PostProcessResult(output="hello")), AI Red Teaming treats the return value as an adapter error.
    # Incorrect — returns a bare string def post_process(context, raw_response): return raw_response.json_body["reply"] # Correct — wrap in the result type def post_process(context, raw_response): return PostProcessResult(output=raw_response.json_body["reply"])
  • Carry state in session_state, not in module-level variables.
    In the adapter runtime, the Python script is not kept running as a persistent process between turns in a conversation. On each turn, that is when each time a message is sent to the target, the runtime reimports and re-executes the script from scratch.
    This means any variable defined at the module level (outside a function) resets to its initial value at the start of every turn. If you assign a value to a module-level variable during one turn, that value is gone by the next turn.
    # Incorrect — module-level state is wiped between turns _SESSION = {} def session_pre_process(context): _SESSION["session_id"] = "abc123" # Correct — return state in session_state; read it from context.session on the next turn def session_pre_process(context): return SessionPreProcessResult(session_state={"session_id": "abc123"})
  • Import only standard library and bundled packages.
    Place all imports at the top of the adapter script.
  • Keep calls bounded.
    Set your own timeouts on anything context.http does not cover. Avoid unbounded loops.

Available Packages

The adapter runner uses Python 3.12 with the full standard library (including json, base64, uuid, time, datetime, hmac, hashlib, and re). Use context.http (backed by httpx) for all HTTP calls rather than importing another client. The websockets package is also bundled for WebSocket targets.
For Google Vertex AI targets (client v1.4.4 or later), the runner also bundles google-auth, google-cloud-aiplatform (including the vertexai namespace), and google-genai. Use them to authenticate to Google Cloud and call a Vertex AI Agent Engine or Gemini target from your adapter.
Other third-party packages are not available. Contact AI Red Teaming to request a package. Where possible, use context.http and the standard library.

Runtime Limits

The adapter runtime enforces these limits on every call. A turn fails if your function raises an exception or exceeds a limit.
LimitValueNotes
Overall execution time per call110 sYour functions must finish within this window.
HTTP timeout for context.http100 sSet your own timeouts on anything context.http does not cover.
Carried state size (auth and session, each)64 KBSerialized. Checked separately for auth and session. Returning more state than this fails the turn.
Reply size10 MBThe whole adapter reply, including any audio_b64. A larger reply fails that turn.
Printed output64 Ki charactersApplies separately to standard output and standard error. Output past the limit is cut off, and a line reading [output truncated: more than N characters] is added.
Audio clips and documents can be tens of megabytes, and the sidecar holds what your script keeps while the target answers. To keep memory use low, pass .b64 to your target as-is, build the request body once, and don't print() payloads. For audio replies, ask your target for a compressed format such as MP3 if it offers one; uncompressed WAV speech passes the 10 MB reply limit after about three minutes.