Class: Riffer::Guardrail
- Inherits:
-
Object
- Object
- Riffer::Guardrail
- Extended by:
- Helpers::ClassNameConverter
- Includes:
- Helpers::ClassNameConverter
- Defined in:
- lib/riffer/guardrail.rb
Overview
Base class for guardrails that process input and output in the agent pipeline.
Subclass this to create custom guardrails:
class MyGuardrail < Riffer::Guardrail
identifier "my_guardrail"
def process_input(, context:)
# Return pass(messages), transform(modified_messages), or block(reason)
pass()
end
def process_output(response, messages:, context:)
# Return pass(response), transform(modified_response), or block(reason)
pass(response)
end
end
Direct Known Subclasses
Constant Summary
Constants included from Helpers::ClassNameConverter
Helpers::ClassNameConverter::DEFAULT_SEPARATOR
Class Method Summary collapse
-
.identifier(value = nil) ⇒ Object
Gets or sets the guardrail identifier.
Instance Method Summary collapse
-
#identifier ⇒ Object
Returns the instance’s identifier.
-
#process_input(messages, context:) ⇒ Object
Processes input messages before they are sent to the LLM.
-
#process_output(response, messages:, context:) ⇒ Object
Processes output response after it is received from the LLM.
Methods included from Helpers::ClassNameConverter
Class Method Details
.identifier(value = nil) ⇒ Object
Gets or sets the guardrail identifier.
value - the identifier to set, or nil to get.
: (?String?) -> String
32 33 34 35 |
# File 'lib/riffer/guardrail.rb', line 32 def identifier(value = nil) return @identifier || class_name_to_path(name) if value.nil? @identifier = value.to_s end |
Instance Method Details
#identifier ⇒ Object
Returns the instance’s identifier.
: () -> String
41 42 43 |
# File 'lib/riffer/guardrail.rb', line 41 def identifier self.class.identifier end |
#process_input(messages, context:) ⇒ Object
Processes input messages before they are sent to the LLM.
Override this method in subclasses to implement input processing.
messages - the input messages. context - optional context passed to the agent.
: (Array, context: untyped) -> Riffer::Guardrails::Result
53 54 55 |
# File 'lib/riffer/guardrail.rb', line 53 def process_input(, context:) pass() end |
#process_output(response, messages:, context:) ⇒ Object
Processes output response after it is received from the LLM.
Override this method in subclasses to implement output processing.
response - the LLM response. messages - the conversation messages. context - optional context passed to the agent.
: (Riffer::Messages::Assistant, messages: Array, context: untyped) -> Riffer::Guardrails::Result
66 67 68 |
# File 'lib/riffer/guardrail.rb', line 66 def process_output(response, messages:, context:) pass(response) end |