ai-lakera-guard
Checks prompts with Lakera Guard before the LLM.
ai-lakera-guardPriority 1028What it does
ai-lakera-guard sends the prompt to Lakera Guard before the model receives it, and with Direction set to output or both, the model's answer too. A request Lakera flags is refused when Action is block, and only logged when it is alert. The refused client receives Request failure message with Deny code.
It scans only what an AI proxy on the same route handles, ai-proxy or ai-proxy-multi. The refusal is answered 200 unless you change Deny code, and client libraries read that as a normal completion, not as an error.
When to use it
- A support chat on your website whose prompts come from anyone, checked for prompt injection before they reach the model.
- A security team that keeps its detectors and thresholds in a Lakera project, named under Project ID, and wants every chat route judged by it.
- A first week on live traffic with Action set to
alert, which logs each flagged prompt and lets it through, before you switch toblock. - Answers of the model that must be checked as well as the prompts, with Direction set to
both.
Not for refusing prompts by patterns you write yourself — see ai-prompt-guard (Allows or denies prompts that match configured patterns), asking your own authorization service whether a request may go on — see forward-auth (Delegates authentication to an external service) or prompts rated by Alibaba Cloud content moderation — see ai-aliyun-content-moderation (Moderates request content with Alibaba Cloud before the LLM).
Set it up
Block prompt injection before it reaches the model
Acts only on a route that also carries ai-proxy or ai-proxy-multi; without a project ID the prompt is judged by Lakera's default policy, which covers more than prompt injection.
Under Basics set API key to <secret> and leave Direction at input. Under Behavior set Deny code to 403 and set Request failure message to This prompt was refused by the content policy.. Under Advanced leave Lakera endpoint at https://api.lakera.ai/v2/guard.
{
"api_key": "<secret>",
"direction": "input",
"deny_code": 403,
"request_failure_message": "This prompt was refused by the content policy.",
"lakera_endpoint": "https://api.lakera.ai/v2/guard"
}
Things to know
- Action —
alertlets a flagged request through, but not one Lakera fails to judge: an error or a timeout follows Fail open under either action. - Direction — With the answer scanned, a streamed answer reaches the client only once the stream has ended. With
alertand Fail open on, the chunks pass at once and the scan is only logged. - Deny code — Only
200to599can be set;600is refused when you save. - Fail mode — Nothing is scanned unless an AI proxy on the same route picked a model first, and the default then lets the request through in silence.
- Lakera endpoint — An address without its scheme,
api.lakera.ai/v2/guardfor example, is refused when you save. - Action — With
block, a prompt Lakera flags is answered with the deny code and the request failure message,403andThis prompt was refused by the content policy.in the example, and a prompt it does not flag reaches the model. - Lakera endpoint — The prompt goes to this address as a
POST; the example names Lakera's own and a private deployment names its own. - AdviceStart with Action set to
alertand read what it logs before you refuse anything withblock.
Settings
The fields as the console shows them, section by section.
Basics
api_keystringRequiredThe Lakera Guard key, sent as a bearer token with every check. Stored on the engine and shown only to roles that manage this object.
project_idstringThe Lakera project whose detectors and thresholds judge the content.
directionstringdefault inputWhich traffic to scan: input for the request, output for the response, or both. Scanning the response holds a streamed answer back until the stream ends, unless Action is alert and Fail open is on, in which case the chunks pass and the scan is only logged.
actionstringdefault blockWhat a flagged request or response gets: block denies it, and alert only logs it and lets it through. Errors and timeouts follow Fail open either way.
Behavior
deny_codeintegerdefault 200The status a blocked request is answered with, where 200 reads as a normal completion to client libraries and a 4xx as an error.
request_failure_messagestringdefault Request blocked by Lakera GuardThe text returned to the caller when a request is blocked.
response_failure_messagestringdefault Response blocked by Lakera GuardThe text returned to the caller when a model response is blocked.
reveal_failure_categoriesbooleandefault falseIncludes the detector categories that flagged the content in the denial response.
fail_modestringdefault skipWhat to do with a request the plugin cannot inspect: skip lets it through, warn also logs it, and error rejects it with 500. Plain traffic that did not pass through an AI proxy is such a request.
fail_openbooleandefault falseOn, a request goes through when Lakera cannot be reached or times out, and off it is denied.
timeoutintegerdefault 5000How long the guard has to answer one scan.
ssl_verifybooleandefault trueChecks the certificate of the Lakera endpoint before content is sent to it.
Advanced
lakera_endpointstringdefault https://api.lakera.ai/v2/guardThe Lakera Guard address the content is sent to, changed only for a private or regional deployment.
pattern
^https?://