Protect my AI chatbot or LLM feature from prompt injection and data leaks
A layered security plan and code-level checklist for LLM endpoints: injection defenses, data leakage controls, abuse limits, and logging.
The prompt
Help me secure an AI feature in my app that sends user input to a large language model.
What the feature does: [e.g. "customer support chat that can look up orders", "summarizes uploaded documents"]
Stack: [framework, model provider, hosting]
What the model can access: [system prompt contents, retrieved documents, databases, tools or APIs it can call, actions it can take]
Who can use it: [public / logged-in users / internal staff]
Data sensitivity and regulations: [e.g. "customer PII, payment data, health data"; GDPR, HIPAA, etc.]
Current code for the endpoint: [PASTE, with keys removed]
Give me:
1. Threat list for my design: direct prompt injection, indirect injection through retrieved documents or web content, system prompt leakage, sensitive data in outputs, excessive tool permissions, cost abuse and denial of service, and harmful content.
2. Controls for each threat, layered: least-privilege tools and data access, server-side authorization checks on every tool call (never trust the model's decision alone), input and output filtering for PII and secrets, separating untrusted content from instructions, human confirmation for risky actions, rate limits and token budgets per user, and output validation for structured responses.
3. Code changes for my endpoint, minimal and commented.
4. Logging and monitoring: what to log, what not to log (sensitive data), and alerts to set.
5. A test set of 10 attack prompts tailored to my feature to run before launch and after every change.
6. Compliance notes: where regulations I named affect data handling. This is general guidance; confirm requirements with my security or legal team.
Be clear that no single filter fully stops prompt injection, so design assuming it will sometimes succeed.
Highlighted [brackets] are blanks to replace with your own details.
Fill in the blanks and use this promptMore Software Development prompts
What to fill in
- framework, model provider, hosting
- public / logged-in users / internal staff
- PASTE, with keys removed
How this prompt is built
This prompt follows the Few-Shot structure (Few-shot prompting). A few-shot prompt includes one or more worked examples of the input and the output you want, so the model can copy the pattern instead of guessing it.
Related prompts
- Break my first coding project into small buildable stepsA milestone plan where every step leaves you with a working program and tells you what to learn next.
- Get unstuck on a coding error with hints instead of the answerA plain-English explanation of your error and step-by-step hints, so you learn to debug instead of copying a fix.
- Write precise TypeScript types for my data and APIsSafer, readable TypeScript types that rule out impossible states, replace unsafe casts, and come with compile-time tests.
- Write a style guide that documents my app's existing design codeReverse-engineers colors, typography, spacing, and component patterns from your codebase into a STYLE_GUIDE.md developers and AI agents can follow.