detectors: add fullmatch matchtype and strip option to StringDetector#1893
Open
xr843 wants to merge 1 commit into
Open
detectors: add fullmatch matchtype and strip option to StringDetector#1893xr843 wants to merge 1 commit into
xr843 wants to merge 1 commit into
Conversation
Adds a "fullmatch" matchtype that flags an output only when the whole (optionally stripped) output equals a trigger string, complementing the existing str/word/startswith substring modes. This supports detectors that check for a complete expected output (e.g. shield models or probes that specify a full expected response) rather than a substring. Also adds a "strip" option (default False) that strips surrounding whitespace from the output before matching, so trailing newlines or spaces from a generator do not break an otherwise exact match. Defaulting to False keeps all existing matchtype behaviour unchanged. Closes NVIDIA#1084 Signed-off-by: xr843 <xianren843@protonmail.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1084.
Adds a
fullmatchmatchtype toStringDetectorthat flags an output only when the whole (optionally stripped) output equals a trigger string, complementing the existingstr/word/startswithsubstring modes. This supports detectors checking for a complete expected output — e.g. shield models, or probes specifying a full expected response — rather than a substring.Also adds a
stripoption (defaultFalse) that strips surrounding whitespace from the output before matching, so trailing newlines/spaces from a generator (ormax_tokensclipping leaving stray whitespace) don't break an otherwise exact match. Per the maintainer discussion on the issue,strip()was independently wanted for the Shields detector.fullmatchuses literal equality (not regex) for consistency with the other literal-string matchtypes. Defaultstrip=Falsekeeps all existing matchtype behavior unchanged. Tests cover fullmatch hit/miss and strip on/off.