nemoguardrails.library.autoalign.actions

View as Markdown

Module Contents

Functions

NameDescription
_autoalign_outcome-
_autoalign_post-
_autoalign_score_outcome-
autoalign_factcheck_infer-
autoalign_factcheck_output_apiCalls Autoalign Factchecker API and checks if the user message is factually answered by the bot message
autoalign_groundedness_inferChecks the groundedness for the text using the given documents and provides a fact-checking score
autoalign_groundedness_output_apiCalls AutoAlign groundedness check API and checks whether the bot message is factually grounded according to given
autoalign_inferChecks whether the given text passes through the applied guardrails.
autoalign_input_apiCalls AutoAlign API for the user message and guardrail configuration provided
autoalign_output_apiCalls AutoAlign API for the bot message and guardrail configuration provided
process_autoalign_outputProcesses the output provided AutoAlign API

Data

DEFAULT_CONFIG

GUARDRAIL_RESPONSE_TEXT

default_groundedness_config

log

API

nemoguardrails.library.autoalign.actions._autoalign_outcome(
result: dict,
target: nemoguardrails.actions.rail_outcome.TransformTarget
) -> nemoguardrails.actions.rail_outcome.RailOutcome
nemoguardrails.library.autoalign.actions._autoalign_post(
http_client: nemoguardrails.http.HTTPClient | None,
request_url: str,
headers: dict[str, str],
request_body: dict[str, typing.Any]
) -> nemoguardrails.http.HTTPResponse
async
nemoguardrails.library.autoalign.actions._autoalign_score_outcome(
score: float,
threshold: float
) -> nemoguardrails.actions.rail_outcome.RailOutcome
nemoguardrails.library.autoalign.actions.autoalign_factcheck_infer(
request_url: str,
user_message: str,
bot_message: str,
guardrails_config: typing.Optional[typing.Dict[str, typing.Any]] = None,
multi_language: bool = False,
http_client: typing.Optional[nemoguardrails.http.HTTPClient] = None
)
async
nemoguardrails.library.autoalign.actions.autoalign_factcheck_output_api(
llm_task_manager: nemoguardrails.llm.taskmanager.LLMTaskManager,
context: typing.Optional[dict] = None,
user_message: typing.Optional[str] = None,
bot_message: typing.Optional[str] = None,
factcheck_threshold: float = 0.0,
show_autoalign_message: bool = True,
http_client: typing.Optional[nemoguardrails.http.HTTPClient] = None
) -> nemoguardrails.actions.rail_outcome.RailOutcome
async

Calls Autoalign Factchecker API and checks if the user message is factually answered by the bot message

Scores below factcheck_threshold block. Configuration, transport, status, and response parsing failures propagate to the caller.

Parameters:

llm_task_manager
LLMTaskManager

Task manager containing the AutoAlign configuration.

context
Optional[dict]Defaults to None

Runtime context containing the user and bot messages.

factcheck_threshold
floatDefaults to 0.0

Minimum score required to allow the response.

show_autoalign_message
boolDefaults to True

Whether to log detected violations.

http_client
Optional[HTTPClient]Defaults to None

Optional caller-owned HTTP client.

Returns: RailOutcome

An allow or block outcome containing the score and threshold.

nemoguardrails.library.autoalign.actions.autoalign_groundedness_infer(
request_url: str,
text: str,
documents: typing.List[str],
guardrails_config: typing.Optional[typing.Dict[typing.Any, typing.Any]] = None,
http_client: typing.Optional[nemoguardrails.http.HTTPClient] = None
)
async

Checks the groundedness for the text using the given documents and provides a fact-checking score

nemoguardrails.library.autoalign.actions.autoalign_groundedness_output_api(
llm_task_manager: nemoguardrails.llm.taskmanager.LLMTaskManager,
context: typing.Optional[dict] = None,
factcheck_threshold: float = 0.0,
show_autoalign_message: bool = True,
bot_message: typing.Optional[str] = None,
relevant_chunks_sep: typing.Optional[typing.List[str]] = None,
http_client: typing.Optional[nemoguardrails.http.HTTPClient] = None,
kwargs = {}
) -> nemoguardrails.actions.rail_outcome.RailOutcome
async

Calls AutoAlign groundedness check API and checks whether the bot message is factually grounded according to given documents

Scores below factcheck_threshold block. Configuration, transport, status, and response parsing failures propagate to the caller.

Parameters:

llm_task_manager
LLMTaskManager

Task manager containing the AutoAlign configuration.

context
Optional[dict]Defaults to None

Runtime context containing the bot message and documents.

factcheck_threshold
floatDefaults to 0.0

Minimum score required to allow the response.

show_autoalign_message
boolDefaults to True

Whether to log detected violations.

http_client
Optional[HTTPClient]Defaults to None

Optional caller-owned HTTP client.

**kwargs
Defaults to {}

Additional action parameters.

Returns: RailOutcome

An allow or block outcome containing the score and threshold.

nemoguardrails.library.autoalign.actions.autoalign_infer(
request_url: str,
text: str,
task_config: typing.Optional[typing.Dict[typing.Any, typing.Any]] = None,
show_toxic_phrases: bool = False,
multi_language: bool = False,
http_client: typing.Optional[nemoguardrails.http.HTTPClient] = None
)
async

Checks whether the given text passes through the applied guardrails.

nemoguardrails.library.autoalign.actions.autoalign_input_api(
llm_task_manager: nemoguardrails.llm.taskmanager.LLMTaskManager,
context: typing.Optional[dict] = None,
user_message: typing.Optional[str] = None,
show_autoalign_message: bool = True,
show_toxic_phrases: bool = False,
http_client: typing.Optional[nemoguardrails.http.HTTPClient] = None,
kwargs = {}
) -> nemoguardrails.actions.rail_outcome.RailOutcome
async

Calls AutoAlign API for the user message and guardrail configuration provided

Guardrail matches block, PII redactions transform the user message, and other results allow it. Configuration, transport, status, and response parsing failures propagate to the caller.

Parameters:

llm_task_manager
LLMTaskManager

Task manager containing the AutoAlign configuration.

context
Optional[dict]Defaults to None

Runtime context containing the user message.

show_autoalign_message
boolDefaults to True

Whether to log detected violations.

show_toxic_phrases
boolDefaults to False

Whether violation messages include toxic phrases.

http_client
Optional[HTTPClient]Defaults to None

Optional caller-owned HTTP client.

**kwargs
Defaults to {}

Additional action parameters.

Returns: RailOutcome

An allow, block, or user-message transform outcome.

nemoguardrails.library.autoalign.actions.autoalign_output_api(
llm_task_manager: nemoguardrails.llm.taskmanager.LLMTaskManager,
context: typing.Optional[dict] = None,
bot_message: typing.Optional[str] = None,
show_autoalign_message: bool = True,
show_toxic_phrases: bool = False,
http_client: typing.Optional[nemoguardrails.http.HTTPClient] = None,
kwargs = {}
) -> nemoguardrails.actions.rail_outcome.RailOutcome
async

Calls AutoAlign API for the bot message and guardrail configuration provided

Guardrail matches block, PII redactions transform the bot message, and other results allow it. Configuration, transport, status, and response parsing failures propagate to the caller.

Parameters:

llm_task_manager
LLMTaskManager

Task manager containing the AutoAlign configuration.

context
Optional[dict]Defaults to None

Runtime context containing the bot message.

show_autoalign_message
boolDefaults to True

Whether to log detected violations.

show_toxic_phrases
boolDefaults to False

Whether violation messages include toxic phrases.

http_client
Optional[HTTPClient]Defaults to None

Optional caller-owned HTTP client.

**kwargs
Defaults to {}

Additional action parameters.

Returns: RailOutcome

An allow, block, or bot-message transform outcome.

nemoguardrails.library.autoalign.actions.process_autoalign_output(
responses: typing.List[typing.Any],
show_toxic_phrases: bool = False
)

Processes the output provided AutoAlign API

nemoguardrails.library.autoalign.actions.DEFAULT_CONFIG = {'pii': {'mode': 'OFF', 'mask': False, 'enabled_types': ['[BANK ACCOUNT NUMBER]'...
nemoguardrails.library.autoalign.actions.GUARDRAIL_RESPONSE_TEXT = {'confidential_info_detection': 'Confidential Information violation', 'gender_bi...
nemoguardrails.library.autoalign.actions.default_groundedness_config = {'groundedness_checker': {'verify_response': False}}
nemoguardrails.library.autoalign.actions.log = logging.getLogger(__name__)