Class: Riffer::Guardrail

Inherits:
Object
  • Object
show all
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
  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

Direct Known Subclasses

Riffer::Guardrails::MaxLength

Instance Method Summary collapse

Instance Method Details

#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



28
29
30
# File 'lib/riffer/guardrail.rb', line 28

def process_input(messages, context:)
  pass(messages)
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



41
42
43
# File 'lib/riffer/guardrail.rb', line 41

def process_output(response, messages:, context:)
  pass(response)
end