Skip to content

FEAT: add ANSI escape output scorers - #2689

Open
Utkarsh Bahuguna (u7k4rs6) wants to merge 1 commit into
microsoft:mainfrom
u7k4rs6:feat/ansi-escape-output-scorers
Open

Utkarsh Bahuguna (u7k4rs6) wants to merge 1 commit into
microsoft:mainfrom
u7k4rs6:feat/ansi-escape-output-scorers

Conversation

@u7k4rs6

Copy link
Copy Markdown
Contributor

Summary

Adds dedicated output scorers for detecting ANSI escape sequences in model outputs, based on the detection patterns used by Garak's AnsiEscape detector.

Changes

  • Added AnsiEscapeOutputScorer

    • Detects raw ANSI escape sequences and C1 control characters in output.
    • Covers CSI (ESC[) and OSC (ESC]) sequences, as well as C1 CSI/OSC characters.
  • Added EscapedAnsiOutputScorer

    • Detects ANSI escape sequences represented as escaped/literal text.
    • Covers \x1b, \033, \u001b, \27, \e, \x9b, and \x9d representations.
  • Added scorer exports through the existing PyRIT scoring package.

  • Added Garak provenance metadata for the detector patterns.

  • Added comprehensive unit tests covering:

    • Positive and negative cases
    • Garak payload parity
    • Raw vs. escaped payload separation
    • Adversarial/non-matching inputs
    • Custom patterns
    • Scoring rationale
    • Memory behavior
    • Python string escaping edge cases
  • Updated the scorer documentation and corresponding Jupyter notebook.

Scope

This PR implements the scorer portion of the ANSI escape support described in #2683. The Garak AnsiEscape scenario and techniques are intentionally left for a follow-up PR.

Part 1 of #2683.

@romanlutz

Copy link
Copy Markdown
Contributor

Is this a duplicate of #2688 ?

@u7k4rs6

Copy link
Copy Markdown
Contributor Author

Roman Lutz (@romanlutz) No, they’re separate. #2688 adds the ANSI output scorers, while #2689 addresses a different part of the ANSI-related work. There’s no duplicate implementation between the two.

@romanlutz

Copy link
Copy Markdown
Contributor

Identical PR title and the same classes mentioned in the description suggest otherwise (?)

Please make the distinction clear.

@u7k4rs6

Copy link
Copy Markdown
Contributor Author

Right, there's significant overlap.
One way I could separate them is to keep AnsiEscapeOutputScorer in #2688 and make #2689 specifically the EscapedAnsiOutputScorer + its tests/integration. Would that distinction make sense, or would you prefer me to close #2689?

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.

2 participants