Skip to content

FIX: Detect modern frontier chat template delimiters in StaticPromptInjectionScorer (#4041) - #4042

Merged
Roman Lutz (romanlutz) merged 4 commits into
microsoft:mainfrom
Kaap10:fix/static-prompt-injection-frontier-templates-4041
Nov 10, 2026
Merged

Roman Lutz (romanlutz) merged 4 commits into
microsoft:mainfrom
Kaap10:fix/static-prompt-injection-frontier-templates-4041

Conversation

@Kaap10

Copy link
Copy Markdown
Contributor

Description

StaticPromptInjectionScorer detects prompt injection attacks across several subcategories using static regex patterns. For chat template delimiter attacks, "Chat Template Injection" previously covered Llama 2, ChatML, Llama 3, Gemma, and Phi, but missed delimiters from several widely evaluated open-weights frontier model families:

  • DeepSeek (V2 / V3 / R1 / Coder): Turn, role, reasoning traces (<|Thought|>), and tool call markers (<|tool calls begin|>, <|tool outputs begin|>), matching both fullwidth \uFF5C and ASCII pipe |.
  • Cohere Command R / Command R+: Turn markers (<|START_OF_TURN_TOKEN|>, <|END_OF_TURN_TOKEN|>) and role headers (<|SYSTEM_TOKEN|>, <|USER_TOKEN|>, <|CHATBOT_TOKEN|>).
  • Mistral / Mixtral Tool Calling: Schema delimiters ([AVAILABLE_TOOLS], [TOOL_CALLS], [TOOL_RESULTS]).

Key changes:

  • Extended the "Chat Template Injection" regex pattern in StaticPromptInjectionScorer._DEFAULT_PATTERNS to detect DeepSeek, Cohere Command R, and Mistral turn/tool delimiters.
  • Added comprehensive unit tests in tests/unit/score/regex/test_static_prompt_injection_scorer.py covering positive detections, lowercase variants, and attribution rationales.
  • Added negative controls ensuring standard English sentences containing words like "available tools" or "tool calls" do not trigger false positives.

Closes #4041

Copilot AI balanced review requested due to automatic review settings November 7, 2026 15:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Kaap10
Vardhman Gupta (Kaap10) requested a balanced review from Copilot November 7, 2026 15:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@romanlutz Roman Lutz (romanlutz) self-assigned this Nov 7, 2026
Support U+2581 and space-separated sentence and tool tokens, including singular call/output boundaries and tool separators. Add isolated token and malformed-boundary regressions.

Co-authored-by: Copilot App <[email protected]>
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Nov 9, 2026
Merged via the queue into microsoft:main with commit 6053ef3 Nov 10, 2026
60 checks passed
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.

BUG: StaticPromptInjectionScorer misses modern frontier chat template delimiters (DeepSeek, Cohere Command R, Mistral)

3 participants