Sub topic 10
Protecting confidential code and prompts
This chapter assumes you have used an AI coding assistant, know Git and code review, and have read the earlier chapters on tool terms and indemnity. It is general education, not legal advice. Check your own contracts and your vendor's current terms.
Why prompts are a disclosure channel
Everything you send to an AI tool leaves your machine. That includes the prompt you type, the files the tool reads for context, error logs you paste, and sometimes your whole repository index. Sending confidential material to a third party can breach a non-disclosure agreement (NDA), a client contract, or your employer's rules. It can also weaken trade secret protection, because a trade secret depends on reasonable steps to keep it secret.
Ownership of the output (covered in the previous chapter) is a separate question from confidentiality of the input. A tool can give you full ownership of its output and still keep, log, or train on what you sent.
What can leak
| Item sent | Typical risk |
|---|---|
| Proprietary source code | Breach of NDA or employment terms, loss of trade secret status |
| API keys, tokens, passwords | Account compromise, since a secret in a prompt is now stored elsewhere |
| Customer data in logs or test fixtures | Privacy law violations, contract breach |
| Client code or specifications | Breach of the client contract, even if the code is not "secret" |
| Internal architecture notes | Disclosure of security-relevant details |
What to check in the tool's terms
Look for these points in the vendor's terms and data-handling documentation:
- Training use. Does the vendor train on your prompts and code? Consumer plans often differ from business plans here.
- Retention. How long are prompts and outputs stored, and can you delete them?
- Human access. Can vendor staff or contractors read your data, for example for abuse review?
- Sub-processors and location. Which other companies handle the data, and in which country?
- Opt-out controls. Are the privacy settings enforced by an administrator, or can each user change them?
Treat the vendor's marketing page as a claim and the signed terms as the commitment. If they disagree, the signed terms control.
Decide what may be sent
A common approach is to classify code and map each class to the tools allowed for it.
Reduce what the tool can see
Technical controls back up the policy, because people make mistakes under deadline pressure.
- Exclude files. Many assistants support an ignore file or a setting that keeps listed paths out of context. Add
.envfiles, key material, and customer data directories. - Scan before commit. Run a secret scanner in a pre-commit hook so credentials never reach the repository the tool indexes.
- Use test data. Replace real records with synthetic ones before pasting logs.
- Prefer approved accounts. Use the organization's managed account, not a personal one, so the business terms and admin controls apply.
The script below is a minimal check that flags likely secrets in the files you are about to share. It is a sketch, not a replacement for a maintained scanner.
import re
import sys
from pathlib import Path
PATTERNS = {
"AWS access key": re.compile(r"AKIA[0-9A-Z]{16}"),
"Private key block": re.compile(r"-----BEGIN [A-Z ]*PRIVATE KEY-----"),
"Generic secret": re.compile(
r"(?i)(api[_-]?key|secret|token|password)\s*[:=]\s*['\"][^'\"]{8,}['\"]"
),
}
found = False
for name in sys.argv[1:]:
text = Path(name).read_text(encoding="utf-8", errors="ignore")
for label, pattern in PATTERNS.items():
if pattern.search(text):
print(f"{name}: possible {label}")
found = True
sys.exit(1 if found else 0)Run it as python check_secrets.py file1.py file2.py. It exits with status 1 when it finds a match.
If something was already sent
Do not assume it is harmless. Rotate any exposed credential immediately, because deleting a prompt does not undo exposure. Then report the incident under your organization's process, since contracts may require notice to a client. Ask the vendor about deletion under its retention terms and record what you did.
Exercise
Your team's vendor contract says the AI tool does not train on business-plan data, and a developer pastes a production database password into a prompt on the company account. What should happen next, and why is the no-training promise not enough?
Show answer
Rotate the password immediately and report the incident under the organization's process. The no-training promise covers one use of the data. The prompt may still be retained, logged, or seen by staff or sub-processors, so the credential must be treated as exposed.