# 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.

- Topic: Software Development
- Framework: Few-Shot
- Level: Advanced
- Tags: AI & Prompting, Legal, Coding, Summarize, Code, Fill-in Template
- Source: https://www.thinkwithprompt.com/prompts/protect-my-ai-chatbot-or-llm-feature-from-prompt-injection-and-data

## Prompt

```text
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.
```

## What to fill in

- framework, model provider, hosting
- public / logged-in users / internal staff
- PASTE, with keys removed

Free to copy and use. From ThinkWithPrompt (https://www.thinkwithprompt.com/), a library of 2,663 curated AI prompts.
