nemoguardrails.library.llama_guard.actions

View as Markdown

Module Contents

Functions

NameDescription
_get_llama_guard_model-
_llama_guard_outcome-
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
parse_llama_guard_responseParses the response from the Llama Guard LLM and returns a tuple of:

Data

log

API

nemoguardrails.library.llama_guard.actions._get_llama_guard_model(
llms: collections.abc.Mapping[str, nemoguardrails.types.LLMModel],
model_name: str
) -> nemoguardrails.types.LLMModel
nemoguardrails.library.llama_guard.actions._llama_guard_outcome(
allowed: bool,
policy_violations: typing.Optional[typing.List[str]]
) -> nemoguardrails.actions.rail_outcome.RailOutcome
nemoguardrails.library.llama_guard.actions.llama_guard_check_input(
llm_task_manager: nemoguardrails.llm.taskmanager.LLMTaskManager,
llms: collections.abc.Mapping[str, nemoguardrails.types.LLMModel],
model_name: str,
context: typing.Optional[dict] = None,
user_message: typing.Optional[str] = None,
kwargs = {}
) -> nemoguardrails.actions.rail_outcome.RailOutcome
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,
llms: collections.abc.Mapping[str, nemoguardrails.types.LLMModel],
model_name: str,
context: typing.Optional[dict] = None,
user_message: typing.Optional[str] = None,
bot_message: typing.Optional[str] = None
) -> nemoguardrails.actions.rail_outcome.RailOutcome
async

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

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__)