Sub topic 3
Keep Secrets and Sensitive Code Out of the Prompt
This chapter assumes you can read code in at least one language and have used a chat-based assistant or an editor or terminal assistant. You also need to be comfortable editing small snippets before you share them.
When you paste code into an assistant, you send it to a service you don't control. The service may log it, store it, or use it under terms you haven't read. Most unfamiliar code you want explained is harmless. Some of it contains credentials, personal data, or proprietary logic. This chapter shows you how to spot those parts and remove them before you ask.
What counts as sensitive
Check each snippet for these categories before you send it.
| Category | Examples | Why it matters |
|---|---|---|
| Credentials | API keys, passwords, tokens, private keys, connection strings | Anyone who sees them can act as you or your service |
| Personal data | Names, emails, customer records in test fixtures | Sharing it may break privacy law or company policy |
| Internal identifiers | Hostnames, internal URLs, account IDs, bucket names | They reveal how your infrastructure is laid out |
| Proprietary logic | Pricing rules, scoring algorithms, unreleased features | It may be a trade secret or covered by your contract |
Credentials are the most urgent. A leaked key can be abused within minutes, and deleting it from a later message does not undo the exposure.
Check your organization's rules first
Many employers restrict which assistants you may use and what you may paste into them. Some approve a specific tool with a data-protection agreement and ban all others. Find out which rules apply before you share any work code. If you can't find a rule, ask. "I didn't know" is a weak defense after a leak.
Also read the privacy settings of the assistant itself. Look for whether your conversations are kept, who can read them, and whether they are used to train future models. Settings differ between free, paid, and enterprise plans.
Share the minimum
Your question rarely needs the whole file. The fib function from the running example needs only its own seven lines. Send the smallest piece that still lets the assistant answer, and leave the rest out.
Here is a realistic case. You want to understand a caching decorator in a file that also holds credentials.
import os
from functools import lru_cache
DB_PASSWORD = "hunter2-prod-7731"
DB_HOST = "db.internal.example-corp.net"
@lru_cache(maxsize=None)
def load_rate(currency):
return fetch_from_db(DB_HOST, DB_PASSWORD, currency)Pasting this as is would expose the password and an internal hostname. The question is about @lru_cache, so the database details add nothing. A safe version keeps the structure and replaces the sensitive values:
from functools import lru_cache
@lru_cache(maxsize=None)
def load_rate(currency):
return fetch_from_db(DB_HOST, DB_PASSWORD, currency)The assistant can still explain the decorator, because the names DB_HOST and DB_PASSWORD show what the code does without revealing the values. Say in your prompt that you removed some lines, so the assistant doesn't guess about them.
Redact consistently
When you can't drop a line, replace its sensitive parts with placeholders that keep the meaning.
- Swap secrets for obvious placeholders such as
REDACTED_API_KEY. - Replace real names and emails with
[email protected]orCustomer A. - Use the same placeholder for the same value everywhere, so the logic still reads correctly.
- Re-read the final text once, line by line, before you send it.
Check the whole payload
Editor and terminal assistants often send more than you type. They may attach open files, nearby files, or the output of commands. Before you ask, find out what the tool will include. Exclude files such as .env, private key files, and anything in a secrets folder, using whatever ignore mechanism your tool provides.
If a secret already leaked
If you pasted a real credential, treat it as compromised. Revoke or rotate it at its source, such as your cloud console or the service that issued it. Then tell whoever owns security for the project. Deleting the chat is not enough, because you can't confirm what was stored.
Exercise
A colleague pastes a 300-line config module into an assistant to ask what one retry helper does. The module contains a hard-coded database URL with a password. Name two things they should have done before sending it, and one thing they should do now.
Show answer
Before sending, they should have cut the snippet down to the retry helper alone, and removed or replaced the database URL and password with placeholders. They could also have checked that their organization allows this assistant. Now they should treat the password as compromised, rotate it at the database, and report the exposure to the project's security contact.
Exercise
You use an editor assistant that automatically includes open files in each request. You have .env open in another tab. What should you check or change before asking your question?
Show answer
Check what the tool attaches to each request. Close the .env tab or exclude the file with the tool's ignore setting, so its secrets are never sent.