Base_guardrails

This module contains functionality related to the the base_guardrails module for augmentation.components.guardrails.

Base_guardrails

BaseGuardrailsEngine

Bases: ABC

Source code in src/augmentation/components/guardrails/base_guardrails.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class BaseGuardrailsEngine(ABC):

    @abstractmethod
    def input_guard(
        self, message: str, is_stream: bool
    ) -> Optional[AgentChatResponse]:
        """
        Check if the input message is allowed based on guardrail rules.
        If it does it returns None, otherwise it returns an AgentChatResponse
        containing a message indicating the input is not allowed.

        Args:
            message: Generated response message to validate
            is_stream: Flag indicating if the response is a stream

        Returns:
            bool: None if the input is allowed, otherwise an AgentChatResponse
            containing a message indicating the input is not allowed.
        """
        pass

    @abstractmethod
    def output_guard(
        self, message: str, is_stream: bool
    ) -> Optional[AgentChatResponse]:
        """
        Check if the output message is allowed based on guardrail rules.
        If it does it returns None, otherwise it returns an AgentChatResponse
        containing a message indicating the output is not allowed.

        Args:
            message: User input message to validate
            is_stream: Flag indicating if the response is a stream

        Returns:
            bool: None if the output is allowed, otherwise an AgentChatResponse
            containing a message indicating the output is not allowed.
        """
        pass

input_guard(message, is_stream) abstractmethod

Check if the input message is allowed based on guardrail rules. If it does it returns None, otherwise it returns an AgentChatResponse containing a message indicating the input is not allowed.

Parameters:
  • message (str) –

    Generated response message to validate

  • is_stream (bool) –

    Flag indicating if the response is a stream

Returns:
  • bool( Optional[AgentChatResponse] ) –

    None if the input is allowed, otherwise an AgentChatResponse

  • Optional[AgentChatResponse]

    containing a message indicating the input is not allowed.

Source code in src/augmentation/components/guardrails/base_guardrails.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
@abstractmethod
def input_guard(
    self, message: str, is_stream: bool
) -> Optional[AgentChatResponse]:
    """
    Check if the input message is allowed based on guardrail rules.
    If it does it returns None, otherwise it returns an AgentChatResponse
    containing a message indicating the input is not allowed.

    Args:
        message: Generated response message to validate
        is_stream: Flag indicating if the response is a stream

    Returns:
        bool: None if the input is allowed, otherwise an AgentChatResponse
        containing a message indicating the input is not allowed.
    """
    pass

output_guard(message, is_stream) abstractmethod

Check if the output message is allowed based on guardrail rules. If it does it returns None, otherwise it returns an AgentChatResponse containing a message indicating the output is not allowed.

Parameters:
  • message (str) –

    User input message to validate

  • is_stream (bool) –

    Flag indicating if the response is a stream

Returns:
  • bool( Optional[AgentChatResponse] ) –

    None if the output is allowed, otherwise an AgentChatResponse

  • Optional[AgentChatResponse]

    containing a message indicating the output is not allowed.

Source code in src/augmentation/components/guardrails/base_guardrails.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
@abstractmethod
def output_guard(
    self, message: str, is_stream: bool
) -> Optional[AgentChatResponse]:
    """
    Check if the output message is allowed based on guardrail rules.
    If it does it returns None, otherwise it returns an AgentChatResponse
    containing a message indicating the output is not allowed.

    Args:
        message: User input message to validate
        is_stream: Flag indicating if the response is a stream

    Returns:
        bool: None if the output is allowed, otherwise an AgentChatResponse
        containing a message indicating the output is not allowed.
    """
    pass