Prompt injection detection for LangGraph
Arcjet prompt injection detection evaluates each incoming prompt for injection patterns inside your application before it reaches the AI provider. Detected attacks are blocked before the AI call is made, protecting both your application behavior and your AI budget.
What is Arcjet?
Arcjet is the AI agent runtime security platform. Discover the agents running in your organization, enforce policy across every action, prompt, and tool call, and keep the evidence to prove what happened. Detect prompt injection, authorize agent tool calls, redact PII, and block bots and abuse.Quick start
Section titled “Quick start”This example screens inbound user text for prompt injection before the model runs.
We assume you already have a LangGraph project set up. For helper options and denial behavior, see the LangGraph agent guard.
Install the dependencies:
# Export your Arcjet API key from https://console.arcjet.comexport ARCJET_KEY="ajkey_..."
npm install @arcjet/guard @langchain/langgraph @langchain/coreCreate the example:
import { launchArcjet, detectPromptInjection } from "@arcjet/guard";import { langgraphAgentContext } from "@arcjet/guard/langgraph/v1";
const arcjet = launchArcjet({ key: process.env.ARCJET_KEY! });const inbound = detectPromptInjection();
export async function screenPrompt( conversationId: string, userText: string,) { const config = { configurable: { thread_id: conversationId } }; const decision = await arcjet.guard({ label: "message.received", rules: [inbound(userText)], ...langgraphAgentContext(config), });
if (decision.conclusion === "DENY" || decision.hasFailedOpen()) { throw new Error("Prompt injection detected – rephrase your message"); }}Then start or invoke the agent with a test prompt.
Requests appear in your Arcjet dashboard in real time.
What next?
Section titled “What next?” Prompt injection detection intro Learn how prompt injection detection works and when to use it.
AI abuse protection Combine with bot detection for complete AI app protection.
AI data loss prevention Prevent PII from entering model context alongside prompt injection protection.
Testing Write tests for your rules.
Get help
Section titled “Get help”Need help with anything? Email support@arcjet.com to get support from our engineering team.