- Request evaluations screen a prompt inline, before it reaches the model.
- Response evaluations screen a model response inline, before it reaches the user.
- Interaction evaluations return a structured verdict for any set of messages, inline or out of band.
The v1 Interactions endpoint (
POST /detection/v1/interactions) remains available for existing integrations. Build new integrations on the v2 endpoints on this page. See Interactions for the v1 endpoint.Before you begin
- Install an SDK and configure credentials. See Installation and Authentication and configuration.
- Set
HIDDENLAYER_CLIENT_IDandHIDDENLAYER_CLIENT_SECRETin your environment, or setHIDDENLAYER_TOKENto a bearer token. Every example on this page reads credentials from the environment. - Your tenant needs an AI Runtime Security license. The v2 evaluation endpoints require Agentic Runtime Security access. See Get started with Agentic Runtime Security.
- No extra packages are needed. The Java examples build payloads with
LinkedHashMapso they run on Java 8.
Authentication and evaluation are region-specific. If your account is in the EU, create the client for the
prod-eu region: environment="prod-eu" in Python, environment: "prod-eu" in TypeScript, or .environment(Environment.PROD_EU) in Java. The default is prod-us.Choose an endpoint
Each SDK exposes the three endpoints on its runtime resource:
The v2 endpoints auto-detect these provider formats: OpenAI Chat Completions, OpenAI Responses, and Anthropic Messages. See Evaluation endpoints for details.
Guard a request inline
Use request evaluations to screen a prompt before your application sends it to the model. You pass the exact request payload you are about to send. HiddenLayer returns a payload in the same provider format:- If the policy allows or redacts, you get back the request (possibly redacted). Forward this returned payload to the model, not your original.
- If the policy blocks, you get back a block message in the provider’s response format. Return it to the user and do not call the model.
200 in every case. A block is signaled only by the hl-runtime-action: BLOCK response header. The plain methods return only the body, so call the endpoint through the SDK’s raw-response accessor to read the header:
The following example is a support assistant for an online store. It screens the request, calls the model, and then screens the response with response evaluations, which work the same way.
call_model (callModel in TypeScript and Java) is a placeholder that returns a fixed OpenAI Chat Completions response. Replace it with your real model call.
hl-runtime-action: BLOCK, and the example prints the block message without calling the model. For an OpenAI Chat Completions request, the block message looks like this (IDs and timestamps vary):
hl-runtime-action header is present only when the policy blocks. On other outcomes the response has no such header.
The block message follows the provider’s response format, and its content may change. Treat it as an opaque provider response and pass it back to your caller. If you need to detect a block in later code, keep the header value instead of inspecting the body.
Evaluate an interaction with tool calls
Use interaction evaluations when you need a structured verdict, when your traffic includes tool calls, or when you evaluate captured traffic after the fact, such as for monitoring or batch analysis. The endpoint returns a result object rather than a payload to forward. Arguments:metadata(required):model,provider, andrequester_idare required.requester_ididentifies the user, service, or agent that sent the prompt.external_session_idis optional and groups calls into a session.interaction(required): either a provider-native payload, or an explicitly described interaction withmessagesand typed content parts. You can also includetools_availableto describe the tools the agent can call, each withname, and optionallydescriptionandparameters(a JSON Schema).- Project ID (optional): the ID or alias of a Console project. HiddenLayer applies that project’s policy. If you omit it, your tenant’s default project and its policy apply. Pass
hl_project_id=in Python,"HL-Project-Id"in TypeScript, or.hlProjectId(...)on the Java request builder.
The following example evaluates one turn of the support assistant: the user asks about an order, the agent calls a
lookup_order tool, and the agent answers from the tool result.
NONE, the threat level NONE, and the detections list is empty, so the example prints only those two lines and the effective interaction. The exact result depends on your project’s policy.
Evaluate a provider-native payload
You don’t have to convert your traffic to the explicitly described format. Pass the payload you sent to or received from the provider as the interaction, and HiddenLayer detects its format. This example evaluates an OpenAI Chat Completions request that tries to extract customer data, and prints the signals found on each message:Read the outcome
The result has three parts:metadata about the evaluation, outcome with the policy decision, and evaluated_interaction with per-message analysis. Python and TypeScript use the field names below. Java uses getters with the same names in camel case, such as result.getOutcome().getThreatLevel(), and returns optional fields as Optional.
outcome.action:NONE(nothing to act on),DETECT(detections reported, payload unchanged),REDACT(payload modified), orBLOCK(the policy blocks the interaction: don’t forward it).outcome.threat_level:NONE,LOW,MEDIUM,HIGH, orCRITICAL.outcome.detections: a list of detections, one per rule that fired. Each hasrule_name, the rule’s display name, such as[System] Prompt Injection in User Input or Tool Resultor[System] System Prompt Extraction Attempt, andrisk_level(LOW,MEDIUM,HIGH, orCRITICAL). The list is empty when no rules fired. A redaction, such as masking a credit card number, can returnREDACTwith an empty list.outcome.effective_interaction: the payload to forward downstream when the action isn’tBLOCK, with any redactions applied. It has the same shape you sent: an explicitly described interaction in, the same form out (with atimestampon each message); a provider-native payload in, the same provider shape out. When the action isREDACT, forward this payload, not your original.evaluated_interaction.messages[].analysis.signals: per-message findings, keyed by signal name, such asprompt_injection,personally_identifiable_information, orcode. Every signal is present on every message, whether or not it found anything.metadata.evaluation_idandmetadata.project: the evaluation’s ID and the project whose policy was applied.
REDACT or BLOCK decision is returned as DETECT, and the effective payload is unchanged.
See Policy for how rules and actions are configured.
Group calls into a session
An agent often makes many model calls to complete one task. To review them together in the Console as one session, tag every call with the same session ID. To pair a request evaluation with its response evaluation, send the sameHL-Roundtrip-Id header on both.
Your application must generate the session ID once, when the workflow starts, and pass it on every call, including calls from tools and sub-agents. HiddenLayer cannot infer that separate calls belong together. If you evaluate a whole turn at once with interaction evaluations, you don’t need a roundtrip ID. See Agentic sessions for the full model.
Beta status
The v2 evaluation endpoints are not beta APIs in these SDK releases (Python 6.0.0, TypeScript 5.0.0, and Java 6.0.0), so calling them emits no beta warning. Other APIs, such as AI Attack Simulation, are still beta and warn the first time you call them. See Version compatibility and upgrades for what beta status means and how each SDK reports it.Common errors and fixes
Interaction evaluations raise a typed error for the statuses the endpoint declares. Request and response evaluations declare none, so an error status from them raises the base error, with the status code on it. A wrong client ID or secret fails earlier, when the SDK exchanges them for an access token, and raisesUnauthorizedError whichever method you called.
The Python typed errors import from
hiddenlayer, and the Java ones from com.hiddenlayer.api.errors. See Error handling for the full hierarchy.
403 Forbidden or missing features
403 Forbidden or missing features
Your tenant or client credential may not have access to Runtime Security or Agentic Runtime Security. Contact your HiddenLayer account representative or Support.
400 Bad Request or 422 Unprocessable Entity
400 Bad Request or 422 Unprocessable Entity
The payload does not match what the endpoint expects. Common causes:
- Sending an explicitly described interaction (typed content parts) to request or response evaluations. Those endpoints accept only provider-native payloads. Use interaction evaluations instead.
- Sending a response payload to request evaluations, or a request payload to response evaluations.
- Missing required
metadatafields, such asrequester_idorprovider.
e.body in Python, err.body in TypeScript, e.body() in Java) for details from the API.Blocked prompts still reach the model
Blocked prompts still reach the model
You are probably calling the plain request evaluation method, which returns only the body. Call it through the raw-response accessor and check the
hl-runtime-action header, as shown in Guard a request inline. In Java, compare header names case-insensitively.Wrong policy applied
Wrong policy applied
Pass the project ID of the project whose policy you want. Without it, your tenant’s default project and its policy apply. An ID or alias that doesn’t match a project isn’t rejected: the default project’s policy applies instead. For interaction evaluations, check
metadata.project in the result to see which project was used.
