Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nemoguardrails/library/self_check/input_check/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def self_check_input(
events: Optional[List[dict]] = None,
llm: Optional[LLMModel] = None,
config: Optional[RailsConfig] = None,
task: Optional[str] = None,
variant: Optional[str] = None,
**kwargs,
) -> RailOutcome:
"""Checks the input from the user.
Expand All @@ -62,7 +62,7 @@ async def self_check_input(
user_input = context.get("user_message")

task = resolve_self_check_task(
task,
variant,
context,
events,
triggered_rail_key="triggered_input_rail",
Expand Down
2 changes: 1 addition & 1 deletion nemoguardrails/library/self_check/input_check/flows.co
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
flow self check input $variant="self_check_input"
$response = await SelfCheckInputAction(task=$variant)
$response = await SelfCheckInputAction(variant=$variant)

if $response.is_blocked
if $system.config.enable_rails_exceptions
Expand Down
4 changes: 2 additions & 2 deletions nemoguardrails/library/self_check/output_check/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def self_check_output(
events: Optional[List[dict]] = None,
llm: Optional[LLMModel] = None,
config: Optional[RailsConfig] = None,
task: Optional[str] = None,
variant: Optional[str] = None,
**kwargs,
) -> RailOutcome:
"""Checks if the output from the bot.
Expand All @@ -67,7 +67,7 @@ async def self_check_output(
bot_thinking = context.get("bot_thinking")

task = resolve_self_check_task(
task,
variant,
context,
events,
triggered_rail_key="triggered_output_rail",
Expand Down
2 changes: 1 addition & 1 deletion nemoguardrails/library/self_check/output_check/flows.co
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
flow self check output $variant="self_check_output"
$response = await SelfCheckOutputAction(task=$variant)
$response = await SelfCheckOutputAction(variant=$variant)

if $response.is_blocked
if $system.config.enable_rails_exceptions
Expand Down
6 changes: 3 additions & 3 deletions nemoguardrails/library/self_check/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_self_check_prompt_task(


def resolve_self_check_task(
task: Optional[str],
variant: Optional[str],
context: Optional[dict],
events: Optional[List[dict]],
triggered_rail_key: str,
Expand All @@ -75,8 +75,8 @@ def resolve_self_check_task(
variant_param: str,
default_task: str,
) -> str:
if task and not task.startswith("$"):
return task
if variant and not variant.startswith("$"):
return variant

context = context or {}
context_task = get_self_check_task_from_rail(
Expand Down
14 changes: 7 additions & 7 deletions tests/test_multiple_self_check_rails.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,9 +784,9 @@ def test_output_fallback_chain_prefers_task_over_default():
assert chat.llm.inference_count == 2


def _resolve_input_task(task=None, context=None, events=None):
def _resolve_input_task(variant=None, context=None, events=None):
return resolve_self_check_task(
task,
variant,
context,
events,
triggered_rail_key="triggered_input_rail",
Expand Down Expand Up @@ -889,7 +889,7 @@ def test_get_self_check_task_from_rail_resolves_custom_and_default_tasks():

def test_resolve_self_check_task_prefers_explicit_task():
task = _resolve_input_task(
task="check_harmful",
variant="check_harmful",
context={"triggered_input_rail": "self check input $variant=check_off_topic"},
)

Expand All @@ -898,7 +898,7 @@ def test_resolve_self_check_task_prefers_explicit_task():

def test_resolve_self_check_task_uses_triggered_rail_context():
task = _resolve_input_task(
task="$variant",
variant="$variant",
context={"triggered_input_rail": "self check input $variant=check_harmful"},
)

Expand All @@ -907,7 +907,7 @@ def test_resolve_self_check_task_uses_triggered_rail_context():

def test_resolve_self_check_task_uses_latest_start_rail_event():
task = _resolve_input_task(
task="$variant",
variant="$variant",
events=[
{"type": "StartInputRail", "flow_id": "self check input $variant=check_off_topic"},
{"type": "SomeOtherEvent", "flow_id": "self check input $variant=ignored"},
Expand All @@ -930,14 +930,14 @@ def test_resolve_self_check_task_uses_start_flow_params():

def test_resolve_self_check_task_defaults_unresolved_placeholders():
assert _resolve_input_task(context={"triggered_input_rail": "self check input"}) == SELF_CHECK_INPUT_DEFAULT_TASK
assert _resolve_input_task(task="$variant") == SELF_CHECK_INPUT_DEFAULT_TASK
assert _resolve_input_task(variant="$variant") == SELF_CHECK_INPUT_DEFAULT_TASK
assert _resolve_input_task() == SELF_CHECK_INPUT_DEFAULT_TASK


def test_bare_triggered_rail_uses_default_over_event_history():
"""Verify a bare triggered rail selects the default task."""
task = _resolve_input_task(
task="$variant",
variant="$variant",
context={"triggered_input_rail": "self check input"},
events=[
{
Expand Down