Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Structured Logging With Redaction

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Structured Logging With Redaction. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Plaid services emit structured log events containing nested dictionaries and lists. Implement a sanitizer that returns a new event with sensitive financial values replaced by "[REDACTED]" before the event is written to logs.

A value must be redacted when either condition holds:

  1. Its dictionary key matches one of the supplied sensitive keys, ignoring case. Replace the entire value, regardless of whether it is a string, number, list, or dictionary.
  2. A string contains an embedded Plaid access token matching access-[A-Za-z0-9_-]+. Replace only the matching token, preserving the rest of the string.

Recursively process dictionaries and lists. Preserve non-sensitive keys, list ordering, scalar values, and the original input object. Inputs are JSON-compatible values: dictionaries with string keys, lists, strings, numbers, booleans, or None.

Constraints

  • 1 <= number of dictionary and list elements <= 10^5
  • Nesting depth is at most 500
  • Dictionary keys are non-empty strings
  • Sensitive-key matching is exact after lowercasing
  • Do not mutate record

Function Signature

def redact_log_event(record, sensitive_keys):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output