nemoguardrails.library.llama_guard.actions

View as Markdown

Module Contents

Functions

NameDescription
llama_guard_check_inputChecks user messages using the configured Llama Guard model
llama_guard_check_outputCheck the bot response using the configured Llama Guard model
llama_guard_check_output_mappingMapping for llama_guard_check_output.
parse_llama_guard_responseParses the response from the Llama Guard LLM and returns a tuple of:

Data

log

API

nemoguardrails.library.llama_guard.actions.llama_guard_check_input(
llm_task_manager: nemoguardrails.llm.taskmanager.LLMTaskManager,
context: typing.Optional[dict] = None,
llama_guard_llm: typing.Optional[nemoguardrails.types.LLMModel] = None,
kwargs = {}
) -> dict
async

Checks user messages using the configured Llama Guard model and the configured prompt containing the safety guidelines.

nemoguardrails.library.llama_guard.actions.llama_guard_check_output(
llm_task_manager: nemoguardrails.llm.taskmanager.LLMTaskManager,
context: typing.Optional[dict] = None,
llama_guard_llm: typing.Optional[nemoguardrails.types.LLMModel] = None
) -> dict
async

Check the bot response using the configured Llama Guard model and the configured prompt containing the safety guidelines.

nemoguardrails.library.llama_guard.actions.llama_guard_check_output_mapping(
result: dict
) -> bool

Mapping for llama_guard_check_output.

Returns: bool

True if the response should be blocked (i.e. if “allowed” is False),

nemoguardrails.library.llama_guard.actions.parse_llama_guard_response(
response: str
) -> typing.Tuple[bool, typing.Optional[typing.List[str]]]

Parses the response from the Llama Guard LLM and returns a tuple of:

  • Whether the response is safe or not.
  • If not safe, a list of the violated policies.
nemoguardrails.library.llama_guard.actions.log = logging.getLogger(__name__)