Skip to content

Commit 36d625e

Browse files
authored
fix: colang 2 issues in community integrations (#1140)
* fix(prompt_security): correct flow actions and syntax * fix(privateai): update PII detection and masking configurations Set `is_system_action` to `False` for `detect_pii` and `mask_pii` actions to align with updated requirements. Remove `@active` decorators from flows in `flows.co` to streamline flow activation logic. * feat(prompt_security): add rails exceptions to colang 2 * feat(prompt_security): add rails exceptions to colang 1
1 parent 74ff456 commit 36d625e

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

nemoguardrails/library/privateai/actions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def detect_pii_mapping(result: bool) -> bool:
3737
return result
3838

3939

40-
@action(is_system_action=True, output_mapping=detect_pii_mapping)
40+
@action(is_system_action=False, output_mapping=detect_pii_mapping)
4141
async def detect_pii(
4242
source: str,
4343
text: str,
@@ -89,7 +89,7 @@ async def detect_pii(
8989
return entity_detected
9090

9191

92-
@action(is_system_action=True)
92+
@action(is_system_action=False)
9393
async def mask_pii(source: str, text: str, config: RailsConfig):
9494
"""Masks any detected PII in the provided text.
9595

nemoguardrails/library/privateai/flows.co

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# INPUT RAILS
44

5-
@active
65
flow detect pii on input
76
"""Check if the user input has PII."""
87
$has_pii = await DetectPiiAction(source="input", text=$user_message)
@@ -14,7 +13,6 @@ flow detect pii on input
1413

1514
# INPUT RAILS
1615

17-
@active
1816
flow detect pii on output
1917
"""Check if the bot output has PII."""
2018
$has_pii = await DetectPiiAction(source="output", text=$bot_message)
@@ -26,7 +24,6 @@ flow detect pii on output
2624

2725
# RETRIVAL RAILS
2826

29-
@active
3027
flow detect pii on retrieval
3128
"""Check if the relevant chunks from the knowledge base have any PII."""
3229
$has_pii = await DetectPiiAction(source="retrieval", text=$relevant_chunks)
@@ -43,7 +40,6 @@ flow detect pii on retrieval
4340

4441
# INPUT RAILS
4542

46-
@active
4743
flow mask pii on input
4844
"""Mask any detected PII in the user input."""
4945
$masked_input = await MaskPiiAction(source="input", text=$user_message)
@@ -54,15 +50,13 @@ flow mask pii on input
5450

5551
# OUTPUT RAILS
5652

57-
@active
5853
flow mask pii on output
5954
"""Mask any detected PII in the bot output."""
6055
$bot_message = await MaskPiiAction(source="output", text=$bot_message)
6156

6257

6358
# RETRIVAL RAILS
6459

65-
@active
6660
flow mask pii on retrieval
6761
"""Mask any detected PII in the relevant chunks from the knowledge base."""
6862
$relevant_chunks = await MaskPiiAction(source="retrieval", text=$relevant_chunks)
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
# INPUT RAILS
22

3-
@active
43
flow protect prompt
54
"""Check if the prompt is valid according to Prompt Security."""
6-
$result = await protect_text(user_prompt=$user_message)
5+
$result = await ProtectTextAction(user_prompt=$user_message)
76
if $result["is_blocked"]
8-
bot inform answer unknown
9-
stop
7+
if $system.config.enable_rails_exceptions
8+
send PromptSecurityRailException(message="Prompt not allowed. The prompt was blocked by the 'protect prompt' flow.")
9+
else
10+
bot inform answer unknown
11+
abort
1012
else if $result["is_modified"]
1113
$user_message = $result["modified_text"]
1214

1315

1416
# OUTPUT RAILS
1517

16-
@active
1718
flow protect response
1819
"""Check if the response is valid according to Prompt Security."""
19-
$result = await protect_text(bot_response=$bot_message)
20+
$result = await ProtectTextAction(bot_response=$bot_message)
2021
if $result["is_blocked"]
21-
bot inform answer unknown
22-
stop
22+
if $system.config.enable_rails_exceptions
23+
send PromptSecurityRailException(message="Response not allowed. The response was blocked by the 'protect response' flow.")
24+
else
25+
bot inform answer unknown
26+
abort
2327
else if $result["is_modified"]
2428
$bot_message = $result["modified_text"]

nemoguardrails/library/prompt_security/flows.v1.co

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ define subflow protect prompt
44
"""Check if the prompt is valid according to Prompt Security."""
55
$result = execute protect_text(user_prompt=$user_message)
66
if $result["is_blocked"]
7-
bot inform answer unknown
7+
if $config.enable_rails_exceptions
8+
create event PromptSecurityRailRailException(message="Prompt not allowed. The prompt was blocked by the 'protect prompt' flow.")
9+
else
10+
bot inform answer unknown
811
stop
912
else if $result["is_modified"]
1013
$user_message = $result["modified_text"]
@@ -16,7 +19,10 @@ define subflow protect response
1619
"""Check if the response is valid according to Prompt Security."""
1720
$result = execute protect_text(bot_response=$bot_message)
1821
if $result["is_blocked"]
19-
bot inform answer unknown
22+
if $config.enable_rails_exceptions
23+
create event PromptSecurityRailException(message="Response not allowed. The response was blocked by the 'protect response' flow.")
24+
else
25+
bot inform answer unknown
2026
stop
2127
else if $result["is_modified"]
2228
$bot_message = $result["modified_text"]

0 commit comments

Comments
 (0)