nemoguardrails.library.patronusai.actions

View as Markdown

Module Contents

Functions

NameDescription
check_guardrail_passCheck if evaluations in the Patronus API response pass based on the success strategy.
parse_patronus_lynx_responseParses the response from the Patronus Lynx LLM and returns a tuple of:
patronus_api_check_outputCheck the user message, bot response, and/or provided context
patronus_api_check_output_mappingMapping for patronus_api_check_output.
patronus_evaluate_requestMake a call to the Patronus Evaluate API.
patronus_lynx_check_output_hallucinationCheck the bot response for hallucinations based on the given chunks
patronus_lynx_check_output_hallucination_mappingMapping for patronus_lynx_check_output_hallucination.

Data

log

API

nemoguardrails.library.patronusai.actions.check_guardrail_pass(
response: typing.Optional[dict],
success_strategy: typing.Literal['all_pass', 'any_pass']
) -> bool

Check if evaluations in the Patronus API response pass based on the success strategy. “all_pass” requires all evaluators to pass for success. “any_pass” requires only one evaluator to pass for success.

nemoguardrails.library.patronusai.actions.parse_patronus_lynx_response(
response: str
) -> typing.Tuple[bool, typing.Union[typing.List[str], None]]

Parses the response from the Patronus Lynx LLM and returns a tuple of:

  • Whether the response is hallucinated or not.
  • A reasoning trace explaining the decision.
nemoguardrails.library.patronusai.actions.patronus_api_check_output(
llm_task_manager: nemoguardrails.llm.taskmanager.LLMTaskManager,
context: typing.Optional[dict] = None
) -> dict
async

Check the user message, bot response, and/or provided context for issues based on the Patronus Evaluate API

nemoguardrails.library.patronusai.actions.patronus_api_check_output_mapping(
result: dict
) -> bool

Mapping for patronus_api_check_output.

Block (return True) if “pass” is False.

nemoguardrails.library.patronusai.actions.patronus_evaluate_request(
api_params: dict,
user_input: typing.Optional[str] = None,
bot_response: typing.Optional[str] = None,
provided_context: typing.Optional[typing.Union[str, typing.List[str]]] = None
) -> typing.Optional[dict]
async

Make a call to the Patronus Evaluate API.

Returns a dictionary of the API response JSON if successful, or None if a server error occurs.

  • Server errors will cause the guardrail to block the bot response

Raises a ValueError for client errors (400-499), as these indicate invalid requests.

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

Check the bot response for hallucinations based on the given chunks using the configured Patronus Lynx model.

nemoguardrails.library.patronusai.actions.patronus_lynx_check_output_hallucination_mapping(
result: dict
) -> bool

Mapping for patronus_lynx_check_output_hallucination.

Block (return True) if “hallucination” is True.

nemoguardrails.library.patronusai.actions.log = logging.getLogger(__name__)