Skip to content

Commit b595fb0

Browse files
committed
PR comments, some test
1 parent 539109a commit b595fb0

File tree

5 files changed

+341
-99
lines changed

5 files changed

+341
-99
lines changed

nemoguardrails/integrations/guardrails_ai/__init__.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

nemoguardrails/integrations/guardrails_ai/guard_actions.py

Lines changed: 0 additions & 51 deletions
This file was deleted.

nemoguardrails/library/guardrails_ai/flows.co

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Define the main input check flow
2+
flow guardrails_ai check input
3+
"""Check input text using relevant Guardrails AI validators."""
4+
# Run jailbreak and toxicity checks on input
5+
$result = await validate_guardrails_ai_detect_jailbreak(text=$user_message)
6+
if not $result.valid
7+
if $system.config.enable_rails_exceptions
8+
send GuardrailsAIException(message="Guardrails AI jailbreak validation failed")
9+
else
10+
bot refuse to respond
11+
abort
12+
13+
$result = await validate_guardrails_ai_toxic_language(text=$user_message)
14+
if not $result.valid
15+
if $system.config.enable_rails_exceptions
16+
send GuardrailsAIException(message="Guardrails AI toxic language validation failed")
17+
else
18+
bot refuse to respond
19+
abort
20+
21+
# Add other relevant input checks, e.g., restrict to topic
22+
# $result = await validate_guardrails_ai_restrict_to_topic(text=$user_message)
23+
# if not $result.valid
24+
# if $system.config.enable_rails_exceptions
25+
# send GuardrailsAIException(message="Guardrails AI topic restriction validation failed")
26+
# else
27+
# bot refuse to respond
28+
# abort
29+
30+
31+
# Define the main output check flow
32+
flow guardrails_ai check output
33+
"""Check output text using relevant Guardrails AI validators."""
34+
# Run PII, competitor, and provenance checks on output
35+
$result = await validate_guardrails_ai_pii(text=$bot_message)
36+
if not $result.valid
37+
if $system.config.enable_rails_exceptions
38+
send GuardrailsAIException(message="Guardrails AI PII validation failed")
39+
else
40+
bot refuse to respond
41+
abort
42+
43+
$result = await validate_guardrails_ai_competitor_check(text=$bot_message)
44+
if not $result.valid
45+
if $system.config.enable_rails_exceptions
46+
send GuardrailsAIException(message="Guardrails AI competitor check validation failed")
47+
else
48+
bot refuse to respond
49+
abort
50+
51+
# Provenance might need different inputs/context
52+
# $result = await validate_guardrails_ai_provenance_llm(text=$bot_message)
53+
# if not $result.valid
54+
# if $system.config.enable_rails_exceptions
55+
# send GuardrailsAIException(message="Guardrails AI provenance validation failed")
56+
# else
57+
# bot refuse to respond
58+
# abort
59+
# Add other relevant output checks
60+
61+
62+
flow bot refuse to respond
63+
bot say "I apologize, but I cannot respond to that as it may contain inappropriate content or violate policy."

0 commit comments

Comments
 (0)