Log Anonymisation


I am trying to write a pre-logging script that redacts each transaction of a session from the logs.

So my goes is to make all inputs read “[Redacted input]” and all bot outputs read “[Redacted output]”.

I’ve used your resource here to get started and write the below code, but when I try to redact any input or output it does it on a word by word basis and not on the entire input/output.

// Remove input and response text
_.getDialogHistoryUtilities().replaceUserInputText(text -> text.replaceAll(".*", "[Redacted input]"));
_.getDialogHistoryUtilities().replaceResponseText(text -> text.replaceAll(".*", "[Redacted output]"));

Here is how it currently functions…

Input: Hello, my name is blah

Current redacted input: [Redacted input] [Redacted input] [Redacted input] [Redacted input] [Redacted input]

Desired redacted input: [Redacted input]

Could anyone please provide any help on how I can achieve the above desired redacted input/output.

Thank you in advance.


You can try "^.*\$" instad of ".*" in the code, as use “.*” only may match twice in a single string:

// Remove input and response text
_.getDialogHistoryUtilities().replaceUserInputText(text -> text.replaceAll("^.*\$", "[Redacted input]"));
_.getDialogHistoryUtilities().replaceResponseText(text -> text.replaceAll("^.*\$", "[Redacted output]"));


1 Like

That did the trick!

Thank you :slight_smile:

1 Like


If you need to redact the full input and output, you can use the following:

_.getDialogHistoryUtilities().replaceUserInputText(text -> "[Redacted input]");
_.getDialogHistoryUtilities().replaceResponseText(text -> "[Redacted input]");

to avoid the Regex issue.