Sub topic 11
Keeping Secrets and Personal Data Out
This chapter assumes you can already share files, selections, and errors with an assistant, and that you know the examples built around stats.py. Here you learn what to remove before any of that context leaves your machine.
Why this matters
Anything you put in a request is sent to a service you do not control. It may be logged, stored in a chat history, or visible to teammates who share the workspace. You cannot reliably take it back. Treat every request as a message you cannot unsend.
The two concept paths that lead here are file context and error context. Both pull in text you did not write by hand, so both can carry sensitive data without you noticing.
What counts as sensitive
| Category | Examples | Where it hides |
|---|---|---|
| Credentials | API keys, passwords, tokens, private keys | `.env` files, config files, hard-coded strings |
| Connection details | Database URLs with passwords, internal hostnames | Settings files, stack traces |
| Personal data | Names, emails, phone numbers, addresses, IDs | Test fixtures, logs, sample data |
| Business data | Customer records, unreleased plans, proprietary algorithms | Data files, comments |
Where leaks usually happen
Most leaks are accidents, not choices. Three habits cause most of them.
- Sharing a whole file when a selection would do. A file that looks harmless may have a key defined near the top, far from the function you care about.
- Pasting raw error output. Tracebacks can include file paths with your username, environment variables, request headers, and URLs with tokens in the query string.
- Attaching whole folders. A folder may include
.env, exported data, or backup files.
A worked example
Suppose the app that calls average fails while loading data. The log line looks like this:
ConnectionError: could not connect to postgres://report_user:[email protected]:5432/customers
File "/home/maria.lopez/projects/reports/load.py", line 12, in load_rowsIf you paste this unchanged, you share a password, an internal hostname, a database name, and a username. The assistant needs none of those to help. Replace them with placeholders that keep the structure:
ConnectionError: could not connect to postgres://USER:PASSWORD@HOST:5432/DBNAME
File "/home/USER/projects/reports/load.py", line 12, in load_rowsThe error type, the line number, and the function name are still there. Those are the parts that matter for diagnosis.
Code has the same problem. This snippet hard-codes a key:
import os
API_KEY = "sk-live-1234567890abcdef" # do not share this line
def get_key() -> str:
return os.environ["API_KEY"]Before sharing, remove the literal key. Better, fix it at the source: read the value from the environment as get_key does, and delete the hard-coded line. If a key was ever shared or committed, treat it as exposed and rotate it, meaning you revoke it and issue a new one.
A pre-send checklist
Read the request once, top to bottom, before you send it. Look for:
- Strings that resemble keys: long random characters, or prefixes such as
sk-,ghp_, orAKIA. password,secret,token, orauthorizationanywhere in the text.- URLs containing
user:pass@or?token=. - Email addresses, names, or IDs in sample data.
- Home-directory paths that include a real username.
Replace each hit with a clear placeholder such as PASSWORD or [email protected]. Use the same placeholder for the same value so the assistant can still follow the logic.
Reduce the risk before it starts
- Keep secrets out of source files. Load them from environment variables or a secrets manager.
- Add
.envand similar files to your ignore list, and to any assistant ignore settings your tool offers, so they are not attached automatically. - Share the smallest piece that answers the question. A selection of two lines exposes less than a whole file.
- Check what the tool attaches on its own, such as open tabs or the current folder, before you send.
Does redaction hurt the answer?
Rarely. The assistant needs the shape of the problem: the error type, the line, the data types, and the task. It does not need real values. If a value does matter, describe it instead: "the password contains a @ character" is enough to explain a URL parsing bug without revealing the password.
Exercise
A traceback contains the line requests.exceptions.HTTPError: 401 for url https://api.example.com/v1/users?token=abc123xyz. Rewrite the line so it is safe to share, and name one thing that should still be kept for diagnosis.
Show answer
Safe version: requests.exceptions.HTTPError: 401 for url https://api.example.com/v1/users?token=TOKEN. Keep the exception type (HTTPError), the status code (401), and the endpoint path, because they show the request was rejected as unauthorized. Also rotate the token if the original was already shared.