nemoguardrails.library.clavata.actions

View as Markdown

Check for matches against a Clavata policy.

Module Contents

Classes

NameDescription
LabelResultResult of a label evaluation
PolicyResultResult of Clavata Policy Evaluation

Functions

NameDescription
clavata_checkCheck for matches against a Clavata policy.
evaluate_with_policyGet the policy result for the given source.
get_clavata_configGet the Clavata config and flow config for the given source.
get_labelsChecks whether the provided text matches the specified Clavata policy ID.
get_policy_idGet Policy ID will check the input policy. If the input is already a UUID, that UUID will be used. Otherwise,
get_server_endpointGet the server endpoint from the Clavata config.
is_label_matchCheck whether the labels matched the policy

Data

VALID_RAILS

ValidRailsType

log

API

class nemoguardrails.library.clavata.actions.LabelResult()

Bases: BaseModel

Result of a label evaluation

label
str = Field(description='The label that was evaluated')
matched
bool
message
str
classmethod

Convert a Clavata section report to a LabelResult

class nemoguardrails.library.clavata.actions.PolicyResult()

Bases: BaseModel

Result of Clavata Policy Evaluation

failed
bool
label_matches
List[LabelResult]
policy_matched
bool
classmethod

Convert a Clavata job to a PolicyResult

classmethod

Convert a Clavata report to a PolicyResult

nemoguardrails.library.clavata.actions.clavata_check(
text: str,
policy: typing.Union[str, None] = None,
labels: typing.Optional[typing.Union[typing.List[str], str]] = None,
rail: typing.Union[nemoguardrails.library.clavata.actions.ValidRailsType, None] = None,
config: typing.Optional[nemoguardrails.RailsConfig] = None,
kwargs: typing.Any = {}
) -> bool
async

Check for matches against a Clavata policy.

nemoguardrails.library.clavata.actions.evaluate_with_policy(
text: str,
policy_id: str,
clavata_config: nemoguardrails.rails.llm.config.ClavataRailConfig
) -> nemoguardrails.library.clavata.actions.PolicyResult
async

Get the policy result for the given source.

nemoguardrails.library.clavata.actions.get_clavata_config(
config: typing.Any
) -> nemoguardrails.rails.llm.config.ClavataRailConfig

Get the Clavata config and flow config for the given source.

nemoguardrails.library.clavata.actions.get_labels(
config: nemoguardrails.rails.llm.config.ClavataRailConfig,
labels: typing.Optional[typing.Union[typing.List[str], str]] = None,
rail: typing.Optional[nemoguardrails.library.clavata.actions.ValidRailsType] = None
) -> typing.List[str]

Checks whether the provided text matches the specified Clavata policy ID. Note that this action will return True if any label in the policy matches the text.

nemoguardrails.library.clavata.actions.get_policy_id(
config: nemoguardrails.rails.llm.config.ClavataRailConfig,
policy: typing.Union[str, None] = None,
rail: typing.Optional[nemoguardrails.library.clavata.actions.ValidRailsType] = None
) -> uuid.UUID

Get Policy ID will check the input policy. If the input is already a UUID, that UUID will be used. Otherwise, the config will be checked to try to match the input policy alias to a policy ID. If no match is found, an error will be raised.

nemoguardrails.library.clavata.actions.get_server_endpoint(
config: nemoguardrails.rails.llm.config.ClavataRailConfig
) -> str

Get the server endpoint from the Clavata config.

nemoguardrails.library.clavata.actions.is_label_match(
result: nemoguardrails.library.clavata.actions.PolicyResult,
labels: typing.List[str],
clavata_config: nemoguardrails.rails.llm.config.ClavataRailConfig
) -> bool

Check whether the labels matched the policy

nemoguardrails.library.clavata.actions.VALID_RAILS = ['input', 'output']
nemoguardrails.library.clavata.actions.ValidRailsType = Literal['input', 'output']
nemoguardrails.library.clavata.actions.log = logging.getLogger(__name__)