← Lesson
Redact Before You Export
Joeven
Run
Reset
Python loads on first run
import re SECRET_RE = re.compile(r"sk-[A-Za-z0-9-]+") BEARER_RE = re.compile(r"Bearer [A-Za-z0-9._-]+") def redact(text): out = SECRET_RE.sub("[REDACTED_KEY]", text) out = BEARER_RE.sub("Bearer [REDACTED]", out) return out raw = "upstream 500, key=sk-live-DEMO-not-real auth=Bearer abc.def" print("RAW would leak") print("SAFE", redact(raw)) print("prompt would see:", redact("use sk-live-DEMO-not-real please"))
Run to execute this in your browser. Nothing is sent to a server.