← All sessions, cheat sheets & labs
Week 4 · Field guide · Prompt-injection defense

Lakera Guard

A real-time AI security API that catches prompt injection and jailbreaks before they reach your model or tools.

prompt-injection defensecommercial APIprovider-agnostic

What it is

A managed classifier for hostile input.

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

Catch injection before it lands.

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

Guard the input, then call the model.

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

Course principle

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.

Use in
Lab 4, as the input gate that detects and blocks injection.
week 4
Pairs with
NeMo Guardrails for broader policy rails around output, dialog, and tools.