class Riffer::Guardrails::Result
Represents the result of a guardrail execution.
Results can be one of three types:
-
pass: Continue with the original data unchanged
-
transform: Continue with transformed data
-
block: Halt execution with a reason
Use the factory methods to create results:
Result.pass(data) Result.transform(data) Result.block(reason, metadata: nil)
Constants
- TYPES
Attributes
The data (for pass/transform) or reason (for block).
Optional metadata for block results.
The result type (:pass, :transform, or :block).
Public Class Methods
Source
# File lib/riffer/guardrails/result.rb, line 56 def block(reason, metadata: nil) new(:block, reason, metadata: metadata) end
Creates a block result that halts execution.
- reason
-
the reason for blocking.
- metadata
-
optional additional information.
Source
# File lib/riffer/guardrails/result.rb, line 71 def initialize(type, data, metadata: nil) raise Riffer::ArgumentError, "Invalid result type: #{type}" unless TYPES.include?(type) @type = type @data = data @metadata = metadata end
Creates a new result.
- type
-
the result type (:pass, :transform, or :block).
- data
-
the data or reason.
- metadata
-
optional metadata for block results.
Raises Riffer::ArgumentError if the result type is invalid.
Source
# File lib/riffer/guardrails/result.rb, line 35 def pass(data) new(:pass, data) end
Creates a pass result that continues with unchanged data.
- data
-
the original data to pass through.
Source
# File lib/riffer/guardrails/result.rb, line 45 def transform(data) new(:transform, data) end
Creates a transform result that continues with transformed data.
- data
-
the transformed data.
Public Instance Methods
Source
# File lib/riffer/guardrails/result.rb, line 99 def block? type == :block end
Returns true if this is a block result.
Source
# File lib/riffer/guardrails/result.rb, line 83 def pass? type == :pass end
Returns true if this is a pass result.
Source
# File lib/riffer/guardrails/result.rb, line 91 def transform? type == :transform end
Returns true if this is a transform result.