Redact Card Numbers From a Streamed Agent Transcript Across Chunk Boundaries
Last updated: November 29, 2026
Quick Overview
Text from a live support conversation arrives in arbitrary chunks. Build a streaming redactor that replaces any run of 13 to 19 digits (optionally separated by single spaces or hyphens) that passes the Luhn check with [CARD], emits output as early as possible, and produces exactly the same result no matter how the text is chunked.
Decagon
November 29, 20260
0
0 solved
Text from a live support conversation arrives in arbitrary chunks. Build a streaming redactor that replaces any run of 13 to 19 digits (optionally separated by single spaces or hyphens) that passes the Luhn check with [CARD], emits output as early as possible, and produces exactly the same result no matter how the text is chunked.
Decagon's agents handle billing and payment conversations on chat and voice transcripts, and card numbers must never reach logs, the model context or analytics, even though tokens stream in a few characters at a time. The interviewer checks that you identify exactly how much text must be held back, prove chunk invariance, and keep latency low for non-digit text.
What the Interviewer Expects
- Defines the candidate pattern and Luhn validation precisely
- Holds back only a trailing run that the next chunk could still extend
- Emits all other text immediately
- Guarantees identical output for any chunking, and tests it with randomized splits
- Handles flush at end of stream
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you bound memory if a malicious user sends an endless digit string?
- How would you extend this to other PII such as SSNs or emails that need lookahead on letters?
- Voice transcripts spell numbers as words ('four one one one'). How do you adapt?
- Where in the pipeline should redaction run relative to the LLM and the logging layer?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
A candidate is a maximal run matching \d([ -]?\d)*. If its digit count is 13 to 19 and it passes Luhn, replace the entire run with [CARD]; otherwise leave it untouched. Output must be a pure funct...
High-Level Design
Keep a buffer. After appending a chunk, find a safe cut: if the buffer ends inside a digit run (or one separator after a digit), that run could still grow, so hold it back from its first character. Ev...