In this lesson
Security starts in the design of the system.
A system with AI can be fooled by hidden text, leak customer data or treat people unequally without anyone noticing. Security comes from decisions you can check, not from a sentence in the instructions.
- Treat outside text as data, never as an order
- Limit what the model can do on its own
- Protect personal data before sending it
When text pretends to be an order
Prompt injection happens when an input changes the model's behavior in a way nobody planned for. Think of a note hidden inside a business letter: whoever reads the whole letter may take the note for an order from the company.
Asking the model to ignore manipulation helps very little. A solid defense combines layers.
- Labeled data: the email comes in as a field in a form, with its origin written next to it.
- Closed output: the answer follows fixed fields. If there is no field for bank data, it has nowhere to appear.
- Least privilege: the model gets only the tools it needs.
- Testing with attacks: a list of malicious emails runs every time the instruction changes.
How much the model can do
The more actions the model can trigger, the greater the damage of a successful attack. Actions that are easy to undo can be automatic. The ones with no way back need a person.
| Action | Who does it |
|---|---|
| Classify and summarize | Automatic |
| Move to a department's queue | Automatic, with a log |
| Reply to the sender | Draft; a person sends it |
| Change a record or delete a file | Out of the model's reach |
Permission is checked in the destination system, never left to the model. If the credential can only classify and move, the worst attack can only classify and move.
Personal data before the prompt
A customer's email usually has a name, a phone number and sometimes a CPF, the Brazilian individual taxpayer number. Sending that to an AI provider is processing of personal data under the LGPD, Brazil's data protection law, and tests count too. Reduce the damage by replacing the data with a tag before sending.
What the pros know
Replacing the CPF with a tag only counts as pseudonymization if the link is kept somewhere else. The LGPD defines pseudonymization as the processing in which the data can only be associated with the person again through the use of additional information kept separately by the controller, in a controlled and secure environment. If the "tag = CPF" table sits in the same file as the text, anyone can undo the replacement, and the protection is only for show. Professionals keep that table in another system, with restricted access.
The answer can be dangerous too
Treat what the model returns as if it came from an unknown user. Never build a database query by joining its text into it: use a fixed query and pass only the values. Never put the text on a page without handling special characters. And never build a file path with it without checking that the file stays inside the allowed folder.
When the provider's filter blocks an input, treat it as a refusal, not as a network failure: send the case to the human queue and count the event. Trying again only spends money.
Third-party files and the incident
Packages and model files that come from outside are a risk. Pickle, a format used to save models in Python, can run code when it loads, and the Python documentation tells you to load only data you trust. Prefer safetensors.
If a secret leaks, the order for the first hour is contain, scope, record and communicate. Containing means changing the key now: a secret that ended up in the git history is still exposed.
Careful
Do not use real customer data to test the triage on a cloud API. Create made-up emails with the same structure.
Practice · 5 min
- Draw the points where outside text comes into your system and write what the model can do at each one.
- Write four test texts: a direct request, a hidden text, a request to reveal the instructions and a text with a CPF.
- List the personal data that would go out in a call to the provider and the tag that would replace each item.
Summary
- Outside text is data. The protection is in the design: closed output and least privilege.
- Actions with no way back stay with a person.
- Pseudonymization requires the link to be kept somewhere else.
- Run a list of attacks at every change.
Sources
Read on October 30, 2026.
- Brazil. Lei 13.709/2018 (LGPD): pseudonymization (article 13, paragraph 4).
- Python. pickle: security warning.
- OWASP. Top 10 for LLM Applications: list of risks.
Lesson quiz
Three situations to apply what you learned.
Isaque Victor free courses