Class: Promptmenot::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/promptmenot/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:, matches: []) ⇒ Result

Returns a new instance of Result.



7
8
9
10
# File 'lib/promptmenot/result.rb', line 7

def initialize(text:, matches: [])
  @text = text
  @matches = matches.freeze
end

Instance Attribute Details

#matchesObject (readonly)

Returns the value of attribute matches.



5
6
7
# File 'lib/promptmenot/result.rb', line 5

def matches
  @matches
end

#textObject (readonly)

Returns the value of attribute text.



5
6
7
# File 'lib/promptmenot/result.rb', line 5

def text
  @text
end

Instance Method Details

#categories_detectedObject



20
21
22
# File 'lib/promptmenot/result.rb', line 20

def categories_detected
  matches.map(&:category).uniq
end

#high_confidence_matchesObject



28
29
30
# File 'lib/promptmenot/result.rb', line 28

def high_confidence_matches
  matches.select { |m| m.confidence == :high }
end

#patterns_detectedObject



24
25
26
# File 'lib/promptmenot/result.rb', line 24

def patterns_detected
  matches.map(&:pattern_name).uniq
end

#safe?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/promptmenot/result.rb', line 12

def safe?
  matches.empty?
end

#summaryObject



32
33
34
35
36
37
38
39
# File 'lib/promptmenot/result.rb', line 32

def summary
  return "No prompt injection detected." if safe?

  count = matches.size
  cats = categories_detected.map { |c| c.to_s.tr("_", " ") }.join(", ")
  "Detected #{count} potential prompt injection pattern#{"s" if count > 1} " \
    "in categories: #{cats}."
end

#unsafe?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/promptmenot/result.rb', line 16

def unsafe?
  !safe?
end