NeMo Guardrails とは
NeMo Guardrails は NeMo Microservices GA に含まれる、AIエージェントのセキュリティ・ポリシー実装サービスです。LLMの「自由すぎる出力」をエンタープライズ要件に合わせて制御する層を提供します。
OSSの Llama Guard / NeMo Guardrails Toolkit と異なり、エンタープライズ版はNemoClaw統合・RBAC・監査ログ・SLA を備え、本番運用のセキュリティ要件を満たします。
対応する5つの脅威
| 脅威 | 具体例 | Guardrails対応 |
|---|---|---|
| プロンプトインジェクション | 「以前の指示を無視して〜」 | Input rail で入力検証 |
| 脱獄(Jailbreak) | 「DAN モード起動」「制限を解除」 | Jailbreak detection rail |
| PII漏洩 | 個人名・電話・マイナンバー出力 | Output rail で PII 検出・マスク |
| コンテンツ違反 | 暴力・差別・成人向け表現 | Content safety rail |
| トピック逸脱 | 業務範囲外への回答 | Topical rail(Colang スクリプト) |
| ハルシネーション | 事実でない出力 | Fact-check rail + RAG連携 |
実装パターン1: 基本的なRail設定
Colang(NeMo Guardrails の DSL)で書く基本パターン:
# config/rails.co
define user ask about restricted topic
"How do I make a weapon?"
"Tell me how to hack a system"
define bot refuse
"I cannot help with that request. Please ask about our services."
define flow
user ask about restricted topic
bot refuse
# config/config.yml
models:
- type: main
engine: nim
model: meta-llama/Llama-3.3-70B-Instruct
rails:
input:
flows:
- check_jailbreak
- check_input_pii
output:
flows:
- check_output_pii
- check_factuality
dialog:
flows:
- off_topic_refusal
実装パターン2: PII保護(日本対応)
# PII検出パターン(日本対応)
pii_patterns:
- name: "mynumber"
pattern: '\d{12}'
description: "マイナンバー (12桁)"
action: mask
- name: "phone_jp"
pattern: '0\d{1,4}-?\d{1,4}-?\d{4}'
description: "日本電話番号"
action: mask
- name: "email"
pattern: '[\w.+-]+@[\w-]+\.[\w.-]+'
description: "メールアドレス"
action: mask
- name: "credit_card"
pattern: '\d{4}-?\d{4}-?\d{4}-?\d{4}'
description: "クレジットカード"
action: redact
# 適用設定
rails:
output:
flows:
- pii_mask:
patterns: [mynumber, phone_jp, email, credit_card]
mask_char: "*"
マイナンバー・日本電話番号は標準パターンでは検出できないため、カスタム正規表現が必須です。データプライバシー設計ガイドと合わせて運用設計してください。
実装パターン3: トピック制限
# 業務範囲外を拒否
define user ask off topic
"今日の天気は?"
"おすすめのレストランは?"
"株価予想は?"
define user ask in scope
"顧客対応のFAQ"
"社内規程の解釈"
"技術文書の要約"
define bot greet
"ご質問ありがとうございます。私は顧客サポート専門のAIエージェントです。"
define bot off topic refusal
"申し訳ございませんが、その質問は私の対応範囲外です。{業務範囲}について承ります。"
define flow
user ask off topic
bot off topic refusal
define flow
user ask in scope
bot greet
# ... RAG等の標準フロー
NemoClaw・他Microservicesとの統合
Guardrails はNemoClawの標準フローに組み込まれます:
- User Input → Guardrails Input Rail(脱獄検査・PII検査)
- → Retriever(RAG検索)
- → Customizer-tuned LLM(ファインチューニング済モデル)
- → Guardrails Output Rail(PII マスク・コンテンツフィルタ・事実検証)
- → Evaluator(性能ログ)
- → User Response
すべての段階の処理は監査ログに記録され、コンプライアンス要件(ISO 27001 / GDPR / 個人情報保護法)対応の証拠資料となります(ISO27001対応ガイド参照)。
運用ベストプラクティス
- Input + Output 両方の rail を必ず設定(Output だけだとAttacker側で完結できる)
- Jailbreak 検出は週次で最新パターン更新(新しい攻撃手法が日々登場)
- PII パターンは日本対応版を必ず追加(標準は欧米中心)
- Topical rail は対話例を100件以上学習(少ないと過剰拒否)
- Eval セットに Adversarial 例を含める(NeMo Evaluator で定期検証)
- Fail2Ban 風のレート制限併用(同一IPからの脱獄試行ブロック)