Privacy and Security

What happens to text you paste into an AI assistant, which data to keep out of prompts, how to redact it, and how to check AI-written code.

14 minLesson 5 of 7
On this page
  1. What happens to a prompt you send
  2. What to keep out of prompts
  3. Redacting text before you paste it
  4. Security risks in what the model produces
  5. Pitfalls and nuances
  6. Check your understanding
  7. What to practise next

Using an AI assistant creates two security problems. The first is that everything you paste into a hosted assistant is sent to a server you do not control, so secrets and other people's personal data can leave your hands. The second is that the output can contain insecure code, packages that do not exist, or commands that do damage, and you are the one who runs it.

A common example is debugging a login problem by pasting a config file and fifty lines of a server log into an assistant. The assistant finds the bug, but the config contains the production database password and the log contains a customer's email address. Both are now stored by a third party.

What happens to a prompt you send

A prompt to a hosted assistant travels to the provider's servers. Depending on the provider, your plan and your settings, it can be kept in your chat history, kept in logs for abuse monitoring or debugging, and in some setups used to improve future models. You usually cannot see which of these apply from inside the chat window.

You Assistant app Provider servers Chat history Logs Training?
Where a pasted prompt can end up. Which of these apply depends on the provider, the plan and the settings.

You can find out the answers once for each tool you use. There are four questions to ask.

  • Is the tool approved for this kind of data? Your employer may allow a tool for source code and forbid it for customer data.
  • Is my data used for training, and can I turn that off? Personal plans and business plans often have different defaults.
  • How long are conversations kept, and does deleting a chat delete it everywhere? Deleting a chat from your history does not always remove it from logs or backups.
  • Who else can see my history? Workspace admins, shared accounts and shared devices all count.

A practical rule is to treat every prompt as an email to an outside contractor. If you would not send the content in that email as it is, redact it first.

What to keep out of prompts

Three kinds of data should not be pasted into a hosted assistant unless the tool has been approved for them.

Secrets are passwords, API keys, access tokens, private keys and connection strings. They are the most damaging to leak because anyone who holds one can act as you, and they are easy to paste by accident inside config files and log lines.

Other people's personal data includes names with contact details, and health, financial or student records. These people did not agree to have their data sent to an AI provider, and in many places the law requires a reason and sometimes a contract before you share it with a third party.

Confidential work includes unreleased plans, contract terms and code that your employer has not cleared for the tool. The risk here is less about attackers and more about breaking your own organization's rules.

In nearly every case the model does not need the real value. To debug a login failure it needs to know that a password is set, not what the password is. Placeholders such as [EMAIL] or [SECRET] give you the same help.

Redacting text before you paste it

For logs and config files, a small script that replaces known patterns is faster and more reliable than checking by eye. The script below applies three rules in order. Each rule replaces one recognizable shape of sensitive text: an email address, a setting whose name ends in password, secret, token or key, and any long unbroken string that looks like a token.

A simple redactor
// Rules run in order. Each replaces one known shape of sensitive text.
const RULES = [
  [/[\w.+-]+@[\w-]+\.[\w.]+/g, "[EMAIL]"],
  [/\b(\w*(?:password|secret|token|key))\s*[=:]\s*\S+/gi, "$1=[SECRET]"],
  [/\b[A-Za-z0-9_-]{32,}\b/g, "[TOKEN]"],
];
 
function redact(text) {
  for (const [pattern, replacement] of RULES) {
    text = text.replace(pattern, replacement);
  }
  return text;
}
import re
 
# Rules run in order. Each replaces one known shape of sensitive text.
RULES = [
    (r"[\w.+-]+@[\w-]+\.[\w.]+", "[EMAIL]"),
    (r"(?i)\b(\w*(?:password|secret|token|key))\s*[=:]\s*\S+", r"\1=[SECRET]"),
    (r"\b[A-Za-z0-9_-]{32,}\b", "[TOKEN]"),
]
 
def redact(text):
    for pattern, replacement in RULES:
        text = re.sub(pattern, replacement, text)
    return text

The trace below runs the three rules over a five-line log. It also shows the limit of this approach, which is that a rule can only catch a shape somebody thought of in advance.

Redacting a log, one rule at a timeUse the arrows or ← → keys
for each (pattern, replacement) in RULES:  text = replace every match of patternreturn text
  1. log
    1ERROR login failed for maria.lopez@example.com
    2db_password=hunter2-Prod!
    3Authorization: Bearer 9f8a7c6e5d4b3a2f1e0d9c8b7a6f5e4d
    4retrying in 30s (attempt 2 of 5)
    5the support login is Tulip88 for now
    rule
    none yet

    1This is the raw log. Line 1 holds an email address, line 2 a password, line 3 an access token, and line 5 a password written in ordinary words.

  2. log
    1ERROR login failed for [EMAIL]
    2db_password=hunter2-Prod!
    3Authorization: Bearer 9f8a7c6e5d4b3a2f1e0d9c8b7a6f5e4d
    4retrying in 30s (attempt 2 of 5)
    5the support login is Tulip88 for now
    rule
    emails

    2Rule 1 matches anything shaped like name@domain.tld and replaces it with [EMAIL]. The model can still see that a login failed, which is all it needs.

  3. log
    1ERROR login failed for [EMAIL]
    2db_password=[SECRET]
    3Authorization: Bearer 9f8a7c6e5d4b3a2f1e0d9c8b7a6f5e4d
    4retrying in 30s (attempt 2 of 5)
    5the support login is Tulip88 for now
    rule
    name = value

    3Rule 2 matches a name that ends in password, secret, token or key, followed by = or : and a value. It hides the value but keeps the name, so you can still see which setting it was.

  4. log
    1ERROR login failed for [EMAIL]
    2db_password=[SECRET]
    3Authorization: Bearer [TOKEN]
    4retrying in 30s (attempt 2 of 5)
    5the support login is Tulip88 for now
    rule
    long tokens

    4Rule 3 matches any unbroken run of 32 or more letters, digits, underscores or hyphens, which is the shape of most tokens. The word Authorization is not in rule 2's list, so this rule is the one that catches line 3.

  5. log
    1ERROR login failed for [EMAIL]
    2db_password=[SECRET]
    3Authorization: Bearer [TOKEN]
    4retrying in 30s (attempt 2 of 5)
    5the support login is Tulip88 for now
    redacted
    3
    missed
    1

    5Three lines are cleaned and line 4 had nothing to remove. Line 5 still contains a password, because it is written as plain words and none of the rules matches that shape. A script catches the patterns you thought of, so you still need to read what you paste.

1 / 5

Keeping placeholders reversible

When the conversation needs to tell people or accounts apart, give each real value its own numbered placeholder, such as [CUSTOMER_1] and [CUSTOMER_2], and keep the mapping on your own machine. The assistant can then say which customer a line refers to, and you swap the real values back into its answer after you read it.

Paste less

Redaction is the second line of defense. The first is to paste less. The error message and the ten lines around it usually give the model everything it needs, and a smaller excerpt also gives it less irrelevant text to be distracted by.

Use a tool that is approved for the data

Some data cannot be redacted without making the question pointless, for example when you need help analyzing a real customer contract. In that case the answer is a tool your organization has approved for that data, which usually means a business or enterprise plan with a contract that limits retention and training, or a model that runs on infrastructure you control. A model running on your own machine or servers does not send text to a third party, but you are then responsible for securing and updating it.

Security risks in what the model produces

AI output often ends up running on your machine or in your product, so it needs the same scrutiny as code from a stranger.

Insecure fixes

If you ask a model to make an error go away, it may suggest turning off certificate verification, opening file permissions to everyone, or building a database query by joining strings together. Each of these makes the error disappear and each opens a security hole. Joining strings into a query is the clearest case: if the query is "... WHERE name = '" + name + "'", a user who types a quote character and extra SQL changes what the query does, and the fix is a parameterized query that sends the value separately. When a suggested fix works by disabling a safety check, find out why the check failed and fix that instead.

Packages that do not exist

Models sometimes recommend a package name that sounds right but was never published. An attacker can register that name and put malicious code in it, and then anyone who installs the suggestion runs it. Before you install anything new, check that the package is the real, maintained project, for example by looking at its repository, its age and its download numbers.

Commands you have not read

A suggested command can delete files, change permissions or download and run a script. Read it before you run it, and be most careful with anything that uses recursive deletion, sudo, or a pipe from a download straight into a shell.

Coding assistants that read your project

Assistants built into an editor or a terminal often send files from your project along with your question, and that can include .env files, key files and test data you never meant to share. Check what the tool includes by default, exclude secret files with whatever ignore mechanism it provides, and keep real credentials out of the working directory where you can, for example by loading them from a secrets manager.

Assistants that have access

An assistant that can read your files, browse the web or act on your accounts can be steered by instructions hidden in the content it reads. The risk grows with the access you give it, so give it only what the task needs. Prompt Injection explains how the attack works.

Pitfalls and nuances

Try it: Clean up a support request

You want help replying to this customer email. Rewrite what you would paste so the assistant can still help, but nothing personal or secret leaves your hands.

Show a sample answer
Safer versionIllustrative example. Real replies vary.
You
Help me write a reply to a customer. Friendly, under 120 words. Their email says: they were charged twice on 3 March for a yearly plan, and the temporary password we sent them does not work. They want both fixed. What I can tell them: the duplicate charge will be refunded within 5 working days, and I'm sending a new password reset link separately. Address them as [NAME].

The assistant needs the situation and not the identity, so the name, email address, account number and card digits are left out because they add nothing. The temporary password is a live secret. Do not send it to any tool, and reset it. Telling the assistant what you are allowed to promise also makes the reply accurate.

Check your understanding

Quick check

You pasted a live API key into a chat an hour ago. What do you do first?

In the tracer, why did line 5 survive redaction?

An assistant fixes your HTTPS error with an option that skips certificate checks. What do you do?

What to practise next

Look up the data settings of the assistant you use most and write down the answers to the four questions. Then continue with Choosing a Model, where privacy is one trade-off alongside quality, speed and cost.