Class: Riffer::Guardrails::Tripwire
- Inherits:
-
Object
- Object
- Riffer::Guardrails::Tripwire
- Defined in:
- lib/riffer/guardrails/tripwire.rb
Overview
Captures information about a blocked guardrail execution.
When a guardrail blocks execution, a Tripwire is created to record the reason, which guardrail triggered it, and which phase it occurred in.
tripwire = Tripwire.new(
reason: "PII detected in input",
guardrail: PiiRedactor,
phase: :before,
metadata: { detected_types: [:email, :phone] }
)
Constant Summary collapse
- PHASES =
: Array
Riffer::Guardrails::PHASES
Instance Attribute Summary collapse
-
#guardrail ⇒ Object
readonly
The guardrail class that triggered the block.
-
#metadata ⇒ Object
readonly
Optional metadata about the block.
-
#phase ⇒ Object
readonly
The phase when the block occurred (:before or :after).
-
#reason ⇒ Object
readonly
The reason for blocking.
Instance Method Summary collapse
-
#initialize(reason:, guardrail:, phase:, metadata: nil) ⇒ Tripwire
constructor
Creates a new tripwire.
-
#to_h ⇒ Object
Converts the tripwire to a hash.
Constructor Details
#initialize(reason:, guardrail:, phase:, metadata: nil) ⇒ Tripwire
Creates a new tripwire.
- reason
-
the reason for blocking.
- guardrail
-
the guardrail class that blocked.
- phase
-
:before or :after.
- metadata
-
optional additional information.
Raises Riffer::ArgumentError if the phase is invalid.
– : (reason: String, guardrail: singleton(Riffer::Guardrail), phase: Symbol, ?metadata: Hash[Symbol, untyped]?) -> void
41 42 43 44 45 46 47 48 |
# File 'lib/riffer/guardrails/tripwire.rb', line 41 def initialize(reason:, guardrail:, phase:, metadata: nil) raise Riffer::ArgumentError, "Invalid phase: #{phase}" unless PHASES.include?(phase) @reason = reason @guardrail = guardrail @phase = phase @metadata = end |
Instance Attribute Details
#guardrail ⇒ Object (readonly)
The guardrail class that triggered the block.
22 23 24 |
# File 'lib/riffer/guardrails/tripwire.rb', line 22 def guardrail @guardrail end |
#metadata ⇒ Object (readonly)
Optional metadata about the block.
28 29 30 |
# File 'lib/riffer/guardrails/tripwire.rb', line 28 def @metadata end |
#phase ⇒ Object (readonly)
The phase when the block occurred (:before or :after).
25 26 27 |
# File 'lib/riffer/guardrails/tripwire.rb', line 25 def phase @phase end |
#reason ⇒ Object (readonly)
The reason for blocking.
19 20 21 |
# File 'lib/riffer/guardrails/tripwire.rb', line 19 def reason @reason end |
Instance Method Details
#to_h ⇒ Object
Converts the tripwire to a hash.
– : () -> Hash[Symbol, untyped]
54 55 56 57 58 59 60 61 |
# File 'lib/riffer/guardrails/tripwire.rb', line 54 def to_h { reason: reason, guardrail: guardrail.name, phase: phase, metadata: } end |