class Riffer::Guardrail
Base class for guardrails that process input and output in the agent pipeline.
Subclass this to create custom guardrails:
class MyGuardrail < Riffer::Guardrail def process_input(messages, context:) # Return pass(messages), transform(modified_messages), or block(reason) pass(messages) end def process_output(response, messages:, context:) # Return pass(response), transform(modified_response), or block(reason) pass(response) end end
Public Instance Methods
Source
# File lib/riffer/guardrail.rb, line 29 def process_input(messages, context:) pass(messages) end
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.
Source
# File lib/riffer/guardrail.rb, line 43 def process_output(response, messages:, context:) pass(response) end
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.
Protected Instance Methods
Source
# File lib/riffer/guardrail.rb, line 76 def block(reason, metadata: nil) Riffer::Guardrails::Result.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/guardrail.rb, line 55 def pass(data) Riffer::Guardrails::Result.pass(data) end
Creates a pass result that continues with unchanged data.
- data
-
the original data to pass through.
Source
# File lib/riffer/guardrail.rb, line 65 def transform(data) Riffer::Guardrails::Result.transform(data) end
Creates a transform result that continues with transformed data.
- data
-
the transformed data.