By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
A trace recorded during a debugging session contains a customer note with an email address and a phone number. Before the trace can go to the shared observability backend, it has to be redacted. Your task is to write the egress redaction step and prove that only the sensitive fields changed.
redact function that replaces one email and one phone number with stable placeholders.import re
EMAIL = re.compile(r"[\w.+-]+@[\w-]+\.[\w.]+")
PHONE = re.compile(r"\+?\d[\d\s-]{8,}\d")
def redact(value: str) -> str:
value = EMAIL.sub("[email]", value)
return PHONE.sub("[phone]", value)
trace = {
"request_id": "req_lab33",
"customer_note": "Dana at dana@example.com asked us to call +1 415 555 0134.",
"agent_note": "No personal data here.",
}
clean = {key: redact(value) for key, value in trace.items()}
print(clean["customer_note"])
print("contains [email]:", "[email]" in clean["customer_note"])
print("contains [phone]:", "[phone]" in clean["customer_note"])
print("other fields unchanged:", clean["agent_note"] == trace["agent_note"])[email], [phone]) so an analyst knows something was removed.Key takeaways
Redact on egress to every observability sink, not inside one logger.
Use fixed, data-class labels and assert both removal and preservation of useful context.
Regex handles structured identifiers; free-text names and addresses need a policy layer.
Any stable pseudonym is still sensitive data and must be governed like it.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.