Repository navigation
FIX: Detect modern LLM chat template tokens in StaticPromptInjectionScorer - #3484
Open
Vardhman Gupta (Kaap10) wants to merge 1 commit into
Open
Vardhman Gupta (Kaap10) wants to merge 1 commit into
Vardhman Gupta (Kaap10) wants to merge 1 commit into
Conversation
Richard Lundeen (richlundeen)
approved these changes
Oct 25, 2026
This branch has not been deployed
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.
Description
StaticPromptInjectionScorerdetects prompt injection attacks using static regex patterns. For chat template delimiter attacks, it specifies:While this pattern covers legacy Llama 2 (
[INST],<<SYS>>) and early ChatML (<|im_start|>), it misses the control and turn delimiter tokens of today's most widely evaluated open-weights model families:<|start_header_id|>and<|end_header_id|>(e.g.,<|start_header_id|>system<|end_header_id|>)<|eot_id|>(End of turn delimiter)<|begin_of_text|><start_of_turn>and<end_of_turn>(e.g.,<start_of_turn>user,<start_of_turn>model)<|end|>(End of turn delimiter)This PR extends the
"Chat Template Injection"pattern to detect these modern chat template control tokens.Fixes #3483
Tests and Documentation
tests/unit/score/regex/test_static_prompt_injection_scorer.pycovering Llama 3 headers/turn tokens, Gemma turn tokens, Phi end tokens, and lowercase variations.<div>turn of phrase</div>,<turn>take your turn</turn>) do not trigger false positives.test_modern_chat_template_rationaleverifying proper attribution to"Chat Template Injection".ruff checkandruff format.