Skip to content

Commit 641fcc4

Browse files
committed
Added docstrings to library flows for better documentation generation
modified: nemoguardrails/library/autoalign/flows.co modified: nemoguardrails/library/content_safety/flows.co modified: nemoguardrails/library/crowdstrike_aidr/flows.co modified: nemoguardrails/library/llama_guard/flows.co modified: nemoguardrails/library/pangea/flows.co modified: nemoguardrails/library/patronusai/flows.co modified: nemoguardrails/library/topic_safety/flows.co modified: nemoguardrails/library/trend_micro/flows.co modified: docs/reference/library-flows.md modified: nemoguardrails/library/autoalign/flows.co modified: nemoguardrails/library/content_safety/flows.co modified: nemoguardrails/library/crowdstrike_aidr/flows.co modified: nemoguardrails/library/llama_guard/flows.co modified: nemoguardrails/library/pangea/flows.co modified: nemoguardrails/library/patronusai/flows.co modified: nemoguardrails/library/topic_safety/flows.co modified: nemoguardrails/library/trend_micro/flows.co modified: scripts/document_flows.py
1 parent 6a3cfd1 commit 641fcc4

10 files changed

Lines changed: 44 additions & 13 deletions

File tree

docs/reference/library-flows.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# NeMo Guardrails Library Flows
22

3-
3+
44
This document lists all available flows in the NeMo Guardrails library.
55

66
## Understanding the tables

nemoguardrails/library/autoalign/flows.co

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
flow autoalign check input
2+
"""Check input using AutoAlign API for guardrails and PII detection/masking."""
23
$input_result = await AutoalignInputApiAction(show_autoalign_message=True)
34
if $input_result["guardrails_triggered"]
45
global $autoalign_input_response
@@ -13,6 +14,7 @@ flow autoalign check input
1314
$user_message = $input_result["pii"]["response"]
1415

1516
flow autoalign check output
17+
"""Check output using AutoAlign API for guardrails and PII detection/masking."""
1618
$output_result = await AutoalignOutputApiAction(show_autoalign_message=True)
1719
if $output_result["guardrails_triggered"]
1820
if $system.config.enable_rails_exceptions
@@ -28,6 +30,7 @@ flow autoalign check output
2830
$bot_message = $pii_message_output
2931

3032
flow autoalign groundedness output
33+
"""Check output groundedness and factuality using AutoAlign fact-checking."""
3134
if $check_facts == True
3235
global $check_facts
3336
$check_facts = False
@@ -37,5 +40,6 @@ flow autoalign groundedness output
3740
bot provide response
3841

3942
flow autoalign factcheck output
43+
"""Fact-check output using AutoAlign API with configurable threshold."""
4044
$threshold = 0.5
4145
$output_result = await autoalign_factcheck_output_api(factcheck_threshold=$threshold, show_autoalign_message=True)

nemoguardrails/library/content_safety/flows.co

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
flow content safety check input $model
2+
"""Check if input is safe according to content safety policy using the specified model."""
23
$response = await ContentSafetyCheckInputAction(model_name=$model)
34

45
global $allowed
@@ -19,6 +20,7 @@ flow content safety check input $model
1920
abort
2021

2122
flow content safety check output $model
23+
"""Check if output is safe according to content safety policy using the specified model."""
2224
$response = await ContentSafetyCheckOutputAction(model_name=$model)
2325
global $allowed
2426
$allowed = $response["allowed"]

nemoguardrails/library/crowdstrike_aidr/flows.co

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

33
flow crowdstrike aidr guard input
4+
"""Guard user input using CrowdStrike AIDR, optionally transforming unsafe content."""
45
$result = await CrowdstrikeAidrGuardAction(mode="input")
56

67
if $result.blocked
@@ -17,6 +18,7 @@ flow crowdstrike aidr guard input
1718
# OUTPUT RAILS
1819

1920
flow crowdstrike aidr guard output
21+
"""Guard bot output using CrowdStrike AIDR, optionally transforming unsafe content."""
2022
$result = await CrowdstrikeAidrGuardAction(mode="output")
2123

2224
if $result.blocked

nemoguardrails/library/llama_guard/flows.co

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
flow llama guard check input
3+
"""Check if input is safe using Llama Guard model for policy violation detection."""
34
$llama_guard_response = await LlamaGuardCheckInputAction
45
global $allowed
56
$allowed = $llama_guard_response["allowed"]
@@ -15,6 +16,7 @@ flow llama guard check input
1516
abort
1617

1718
flow llama guard check output
19+
"""Check if output is safe using Llama Guard model for policy violation detection."""
1820
$llama_guard_response = await LlamaGuardCheckOutputAction
1921
global $allowed
2022
$allowed = $llama_guard_response["allowed"]

nemoguardrails/library/pangea/flows.co

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

33
flow pangea ai guard input
4+
"""Guard user input using Pangea AI Guard, optionally transforming unsafe content."""
45
$result = await PangeaAiGuardAction(mode="input")
56

67
if $result.blocked
@@ -17,6 +18,7 @@ flow pangea ai guard input
1718
# OUTPUT RAILS
1819

1920
flow pangea ai guard output
21+
"""Guard bot output using Pangea AI Guard, optionally transforming unsafe content."""
2022
$result = await PangeaAiGuardAction(mode="output")
2123

2224
if $result.blocked

nemoguardrails/library/patronusai/flows.co

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
flow patronus lynx check output hallucination
3+
"""Detect hallucinations in bot output using Patronus Lynx with reasoning traces."""
34
$patronus_lynx_response = await PatronusLynxCheckOutputHallucinationAction
45
global $hallucination
56
$hallucination = $patronus_lynx_response["hallucination"]
@@ -15,6 +16,7 @@ flow patronus lynx check output hallucination
1516
abort
1617

1718
flow patronus api check output
19+
"""Evaluate bot output quality using Patronus API evaluator."""
1820
$patronus_response = await PatronusApiCheckOutputAction
1921
global $evaluation_passed
2022
$evaluation_passed = $patronus_response["pass"]

nemoguardrails/library/topic_safety/flows.co

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
flow topic safety check input $model
2+
"""Check if user input is on-topic using the specified topic safety model."""
23
$response = await TopicSafetyCheckInputAction(model_name=$model)
34

45
global $on_topic

nemoguardrails/library/trend_micro/flows.co

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# INPUT AND/OR OUTPUT RAIL
22
flow trend ai guard input $text
3+
"""Guard input text using Trend Micro AI Guard for threat detection."""
34
$result = await TrendAiGuardAction(text=$text)
45

56
if $result.blocked # Fails open if AI Guard service has an error
@@ -12,6 +13,7 @@ flow trend ai guard input $text
1213

1314
# OUTPUT RAIL
1415
flow trend ai guard output $text
16+
"""Guard output text using Trend Micro AI Guard for threat detection."""
1517
$result = await TrendAiGuardAction(text=$text)
1618

1719
if $result.blocked # Fails open if AI Guard service has an error

scripts/document_flows.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def _get_title() -> str:
4040
def _get_preamble() -> str:
4141
"""Get the common dependency explanation text."""
4242
return """
43-
43+
4444
This document lists all available flows in the NeMo Guardrails library.
4545
4646
## Understanding the tables
@@ -84,9 +84,11 @@ def _get_preamble() -> str:
8484
8585
"""
8686

87+
8788
CHECK = "✔"
8889
CROSS = "✗"
8990

91+
9092
@dataclass
9193
class Flow:
9294
"""Represents a Colang flow."""
@@ -100,6 +102,7 @@ class Flow:
100102
uses_llm: bool = False # Uses LLM from config.models
101103
actions: List[str] = field(default_factory=list) # List of actions called by this flow
102104

105+
103106
class FlowAnalyzer:
104107
"""Analyzes Colang flow files and categorizes flows."""
105108

@@ -133,7 +136,13 @@ class FlowAnalyzer:
133136
re.compile(r"await\s+llm\."),
134137
]
135138

136-
def __init__(self, library_path: Path, provider_list_path: Optional[Path], project_root: Path, output_path: Optional[Path] = None):
139+
def __init__(
140+
self,
141+
library_path: Path,
142+
provider_list_path: Optional[Path],
143+
project_root: Path,
144+
output_path: Optional[Path] = None,
145+
):
137146
self.library_path = library_path
138147
self.provider_list_path = provider_list_path
139148
self.project_root = project_root
@@ -624,6 +633,7 @@ def _get_relative_path(self, target_path: str) -> str:
624633
except ValueError:
625634
# Paths don't share a common base, use os.path.relpath
626635
import os
636+
627637
return os.path.relpath(str(target), str(output_dir))
628638

629639
def _format_table_header(self, category_key: str, category_title: str, header_prefix: str) -> List[str]:
@@ -635,7 +645,9 @@ def _format_table_header(self, category_key: str, category_title: str, header_pr
635645
output.append("")
636646
return output
637647

638-
def _format_table_asciidoc(self, category_key: str, category_title: str, flows: List[Flow], include_links: bool = False) -> List[str]:
648+
def _format_table_asciidoc(
649+
self, category_key: str, category_title: str, flows: List[Flow], include_links: bool = False
650+
) -> List[str]:
639651
"""Format a table in AsciiDoc format."""
640652
output = self._format_table_header(category_key, category_title, "==")
641653
output.append('[cols="2,1,1,1,2,6", options="header"]')
@@ -667,19 +679,23 @@ def _format_table_asciidoc(self, category_key: str, category_title: str, flows:
667679
else:
668680
examples = "N/A"
669681

670-
output.append(
671-
f"| `{flow.name}` | {library} | {llm_usage} | {requires_external} | {desc} | {examples}"
672-
)
682+
output.append(f"| `{flow.name}` | {library} | {llm_usage} | {requires_external} | {desc} | {examples}")
673683

674684
output.append("|===")
675685
output.append("")
676686
return output
677687

678-
def _format_table_markdown(self, category_key: str, category_title: str, flows: List[Flow], include_links: bool = False) -> List[str]:
688+
def _format_table_markdown(
689+
self, category_key: str, category_title: str, flows: List[Flow], include_links: bool = False
690+
) -> List[str]:
679691
"""Format a table in Markdown format."""
680692
output = self._format_table_header(category_key, category_title, "##")
681-
output.append("| Flow Name | Library (`nemoguardrails/library/...`) | Requires a Configured LLM | Requires External Server Calls | Description | Example Configs |")
682-
output.append("|-----------|----------------------------------------|---------------------------|--------------------------------|-------------|-----------------|")
693+
output.append(
694+
"| Flow Name | Library (`nemoguardrails/library/...`) | Requires a Configured LLM | Requires External Server Calls | Description | Example Configs |"
695+
)
696+
output.append(
697+
"|-----------|----------------------------------------|---------------------------|--------------------------------|-------------|-----------------|"
698+
)
683699

684700
for flow in sorted(flows, key=lambda f: (f.library, f.name)):
685701
llm_usage = CHECK if flow.uses_llm else CROSS
@@ -704,9 +720,7 @@ def _format_table_markdown(self, category_key: str, category_title: str, flows:
704720
else:
705721
examples = "N/A"
706722

707-
output.append(
708-
f"| `{flow.name}` | {library} | {llm_usage} | {requires_external} | {desc} | {examples} |"
709-
)
723+
output.append(f"| `{flow.name}` | {library} | {llm_usage} | {requires_external} | {desc} | {examples} |")
710724

711725
output.append("")
712726
return output

0 commit comments

Comments
 (0)