Skip to content

detectors: add fullmatch matchtype and strip option to StringDetector#1893

Open
xr843 wants to merge 1 commit into
NVIDIA:mainfrom
xr843:detector/stringdetector-fullmatch-strip
Open

detectors: add fullmatch matchtype and strip option to StringDetector#1893
xr843 wants to merge 1 commit into
NVIDIA:mainfrom
xr843:detector/stringdetector-fullmatch-strip

Conversation

@xr843

@xr843 xr843 commented Jun 27, 2026

Copy link
Copy Markdown

Closes #1084.

Adds a fullmatch matchtype to StringDetector 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 checking for a complete expected output — e.g. shield models, or probes specifying 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/spaces from a generator (or max_tokens clipping 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.

fullmatch uses literal equality (not regex) for consistency with the other literal-string matchtypes. Default strip=False keeps all existing matchtype behavior unchanged. Tests cover fullmatch hit/miss and strip on/off.

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>
@jmartin-tech jmartin-tech changed the title detectors: add fullmatch matchtype and strip option to StringDetector (#1084) detectors: add fullmatch matchtype and strip option to StringDetector Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

detector: StringDetector matchtype fullmatch

1 participant