Detect Attack
Glaider helps identify and prevent potential prompt injection attacks that could manipulate AI model behavior. It provides options for asynchronous processing, metadata inclusion, tagging, session tracking, message saving, strictness levels, and notifications to enhance functionality and integration with your applications.
Endpoint
Headers
Header | Value |
---|---|
Authorization | Bearer YOUR_API_KEY |
Content-Type | application/json |
Authentication
Replace YOUR_API_KEY
with your actual API key.
Request Body Parameters
Parameter | Type | Required | Description |
---|---|---|---|
prompt | string | Yes | The input text to be analyzed for potential prompt injection. |
zero_latency | boolean | No | If true , the request returns immediately, and processing is done asynchronously. Defaults to false . |
tag | string | No | A custom tag or identifier for the request, useful for tracking and categorization. Defaults to "unknown" . |
chat_id | string | No | An identifier for the chat session or conversation. Useful for associating the analysis with a specific session. |
save_message | boolean | No | If true , the prompt message will be saved in the system for future reference or auditing. Defaults to false . |
notifications | boolean | No | If true , notifications will be sent based on the analysis result. Useful for alerting admins or triggering workflows. Defaults to false . |
strictness | integer | No | Controls the strictness level of detection. Accepts 1 , 2 , or 3 . See Strictness Levels for details. Defaults to None . |
metadata | object | No | A JSON object containing additional data or context for the request. Defaults to {} . |
Notes:
- All boolean parameters default to
false
if omitted. - The
strictness
parameter defaults toNone
if not provided, which uses the default detection behavior. - The
metadata
parameter defaults to an empty object{}
if not provided.
Strictness Levels
The strictness
parameter controls when advanced detection is performed:
- Level 1 (
strictness = 1
): Advanced detection is performed only if the initial detection indicates a potential prompt injection. - Level 2 (
strictness = 2
): Advanced detection is always performed, regardless of the initial detection result. - Level 3 (
strictness = 3
): Advanced detection is performed only if the initial detection does not indicate a prompt injection.
Using higher strictness levels may result in longer processing times due to additional computation required for advanced detection.
Example Request
Responses
Success Response (Synchronous)
- Status Code:
200 OK
- Content-Type:
application/json
- Body:
Accepted Response (Asynchronous)
- Status Code:
202 Accepted
- Content-Type:
application/json
- Body:
Error Responses
400 Bad Request
403 Forbidden
429 Too Many Requests
500 Internal Server Error
Response Fields Description
status
(string
): Indicates the status of the request ("success"
,"pending"
, or"error"
).result
(object
): Contains the detection result (present in synchronous responses).is_prompt_injection
(boolean
):true
if prompt injection was detected,false
otherwise.prompt
(string
ornull
): The analyzed prompt, included ifsave_message
istrue
.timestamp
(string
): The timestamp when the analysis was performed, in ISO 8601 format.tag
(string
): The tag associated with the request.analysis_id
(string
): Unique identifier for the analysis; can be used to retrieve results later.chat_id
(string
ornull
): The chat session identifier, if provided.metadata
(object
ornull
): The metadata provided in the request, if any.notifications
(boolean
): Indicates whether notifications were enabled.strictness
(integer
ornull
): The strictness level used in the analysis.initial_detection_label
(string
): Classification label of the initial detection ("INJECTION"
or"SAFE"
).initial_detection_score
(number
ornull
): Confidence score of the initial classification (between0
and1
).advanced_detection_result
(boolean
ornull
): Result of the advanced detection (true
if injection detected,false
if not,null
if advanced detection not performed).
message
(string
): Additional information or error message.
Parameter Details
-
prompt
: The text input that will be analyzed for potential prompt injections. This field is required. -
zero_latency
: When set totrue
, the endpoint will not wait for the analysis to complete. Instead, it will immediately return a response with astatus
of"success"
and amessage
indicating that processing is occurring in the background. Use the providedanalysis_id
to retrieve the analysis result later via the/analysis-result
endpoint. -
tag
: A user-defined string for labeling or categorizing the request. It’s useful for tracking purposes or analytics within your application. -
chat_id
: An identifier for the chat session or conversation. If provided, it can help associate the analysis result with a specific session in your application. -
save_message
: Iftrue
, the prompt message will be stored in the system. This is useful for auditing, compliance, or future analysis. -
notifications
: Iftrue
, the system will send notifications based on the analysis result. Notifications might include alerts to administrators or triggering automated workflows. -
strictness
: Controls when advanced detection is performed:- Level 1 (
strictness = 1
): Advanced detection is performed only if the initial detection indicates a potential prompt injection. - Level 2 (
strictness = 2
): Advanced detection is always performed. - Level 3 (
strictness = 3
): Advanced detection is performed only if the initial detection does not indicate a prompt injection.
If
strictness
is omitted or set tonull
, default detection behavior is used without advanced detection. - Level 1 (
-
metadata
: An optional JSON object containing additional data or context for the request. This metadata can include any information that you want to associate with the analysis, such as user identifiers, session details, or custom notes. The contents ofmetadata
are not processed by the API but are stored and returned in the results for your reference.
Usage Examples
Detecting Prompt Injection with Metadata (Synchronous)
Detecting Prompt Injection with Asynchronous Processing and Metadata
Retrieving Analysis Results
If you use asynchronous processing by setting zero_latency
to true
, you will receive an analysis_id
in the response. You can retrieve the analysis result using this ID through the /analysis-result
endpoint.
Fetching Analysis Result
Additional Information
-
Rate Limiting: The API enforces rate limits to ensure fair usage. If you exceed the rate limit, you will receive a
429 Too Many Requests
response. Please implement appropriate retry logic with exponential backoff in your applications. -
Error Handling: Always check the
status
field in the response. If it’s"error"
, refer to themessage
field for details. -
Security: Keep your API key secure. Do not expose it in client-side code, public repositories, or logs.
-
Support: For assistance or inquiries, contact our support team at info@glaider.it.
Notes
-
Data Privacy: If you enable
save_message
, ensure you comply with data protection regulations and policies relevant to your organization and jurisdiction. -
Notifications: The nature of notifications (e.g., email alerts, webhook triggers) depends on your account configuration. Contact support to set up notifications.
Example Scenario:
You have a chat application and want to analyze user prompts for potential prompt injection attacks with varying levels of strictness based on the user’s role or the sensitivity of the conversation. By including the metadata
parameter, you can attach additional context to each request, such as the user’s ID, session details, or custom flags. This allows you to correlate analysis results with specific users or sessions, enhancing your security monitoring and incident response processes.
By adjusting the strictness
parameter, you can control the trade-off between detection accuracy and processing time. For high-risk interactions, you might set strictness
to 2
to always perform advanced detection, ensuring maximum security.
Also, by setting zero_latency
to true
, your application can quickly respond to the user while the analysis happens in the background. If a prompt injection is detected, and notifications
is set to true
, your system can receive an alert to take appropriate action, such as logging the event or notifying a moderator.