The Knuth-Morris-Pratt (KMP) algorithm is a string matching algorithm that searches for occurrences of a pattern string in a text string in linear time, i.e., `O(n)`, where `n` is the length of the text string. The algorithm was developed by Donald Knuth and Vaughan Pratt, and later modified by James Morris.

The basic idea behind the KMP algorithm is to use the information about the pattern string that has already been matched to avoid unnecessary backtracking in the text string. Specifically, the algorithm builds a partial match table (also called failure function or prefix function), which indicates for each position in the pattern string the length of the longest proper suffix that is also a prefix of the substring ending at that position.

This table allows the algorithm to skip over certain positions in the text string that cannot possibly match the pattern string, based on the characters that have already been matched. If a mismatch occurs at a particular position in the pattern string, the algorithm uses the information in the partial match table to determine the next position to start matching the pattern string from, without having to backtrack all the way to the beginning of the pattern string.
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence