nemoguardrails.library.prompt_security.actions
nemoguardrails.library.prompt_security.actions
Prompt/Response protection using Prompt Security.
Module Contents
Functions
Data
API
Protects the given user_prompt or bot_response. Args: user_prompt: The user message to protect. bot_response: The bot message to protect. Returns: A dictionary with the following items:
- is_blocked: True if the text should be blocked, False otherwise.
- is_modified: True if the text should be modified, False otherwise.
- modified_text: The modified text if is_modified is True, None otherwise. Raises: ValueError is returned in one of the following cases:
- If PS_PROTECT_URL env variable is not set.
- If PS_APP_ID env variable is not set.
- If no user_prompt and no bot_response is provided.
Mapping for protect_text action.
Returns: bool
True if the response should be blocked (i.e. if “is_blocked” is True),
Calls Prompt Security Protect API asynchronously.
Parameters:
the URL of the protect endpoint given by Prompt Security.
//[REGION].prompt.security/api/protect where REGION is eu, useast or apac
the application ID given by Prompt Security (similar to an API key).
//[REGION].prompt.security/ where REGION is eu, useast or apac
the user message to protect.
the system message for context.
the bot message to protect.
the user ID or username for context.
Returns:
A dictionary with the following items: