$ lexprog.com

// notes from an old coder -- php, databases, and the occasional rant

[November 24, 2026] AI

Redact Secrets Before They Enter Context

Strip API keys, cookies, and .env values before any message is sent. Providers retain prompts under their retention policy.

────────────────────────────────────────────────────────

Redact Secrets Before They Enter Context

Tip: The prompt is a log

Strip API keys, cookies, and .env values before any message is sent. Providers retain prompts under their retention policy.

safe = SECRET_RE.sub('[REDACTED]', user_paste)
messages.append({'role': 'user', 'content': safe})

Gotcha: Tool results re-introduce the secret

A cat .env tool call puts the key back into the next turn. Block those paths in the tool itself.

tools.run('cat .env')

Source: https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/overview

────────────────────────────────────────────────────────
<-- back to posts