A real-time AI security API that catches prompt injection and jailbreaks before they reach your model or tools.
What it is
Lakera Guard is a real-time AI security API. In a single call it runs ML-based detection for prompt injection, jailbreak attempts, PII, and malicious links. Because it is model-based rather than a list of regexes, it catches semantic attacks: the phrasing that means "ignore your instructions" even when the exact words are new. It is provider-agnostic, so it sits in front of whichever model you call.
The one job
Screen every piece of untrusted text, whether typed by the user or pulled from a document, and flag it before it becomes part of a prompt or triggers a tool. It is the gate that stops an attack from ever reaching the model.
Reach for it when
Skip it when
A minimal look
import OpenAI from "openai";
const openai = new OpenAI();
async function answer(userText) {
// screen untrusted input BEFORE it becomes a prompt
const verdict = await guard(userText);
if (verdict.flagged) throw new Error("blocked: prompt injection");
return openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: userText }],
});
}
The principle it teaches
OWASP LLM01: treat every input as hostile. This is the exact threat Lab 4 makes the agent refuse, and Lakera is the managed way to detect it before it ever touches the model.
Where it fits your labs
This is a Week 4 tool. When Lab 4 asks the agent to refuse an injected instruction, Lakera is the input gate that catches the attack rather than trusting the model to notice it.