メインコンテンツまでスキップ

ガードレールAIスコアラー

Guardrails AIは、安全性、個人情報検出、コンテンツ品質などに関する検証を行うコミュニティ主導の検証ハブを使用して、LLMの出力を検証するためのフレームワークです。MLflowはGuardrails AIと統合されているため、Guardrailsのバリデーターをスコアラーとして使用でき、LLM呼び出しを必要とせずにルールベースの評価を提供できます。

要件

guardrails-aiパッケージをインストールしてください。

Python
%pip install guardrails-ai

クイックスタート

Guardrails AIスコアラーを直接呼び出すには:

Python
from mlflow.genai.scorers.guardrails import ToxicLanguage

scorer = ToxicLanguage(threshold=0.7)
feedback = scorer(
outputs="This is a professional and helpful response.",
)

print(feedback.value) # "yes" or "no"

mlflow.genai.evaluate()を使用してGuardrails AIスコアラーを呼び出すには:

Python
import mlflow
from mlflow.genai.scorers.guardrails import ToxicLanguage, DetectPII

eval_dataset = [
{
"inputs": {"query": "What is MLflow?"},
"outputs": "MLflow is an open-source AI engineering platform for agents and LLMs.",
},
{
"inputs": {"query": "How do I contact support?"},
"outputs": "You can reach us at support@example.com or call 555-0123.",
},
]

results = mlflow.genai.evaluate(
data=eval_dataset,
scorers=[
ToxicLanguage(threshold=0.7),
DetectPII(),
],
)

利用可能なガードレールAIスコアラー

安全性とコンテンツの品質

これらの評価者は、LLMの出力結果について、安全性、個人情報保護、およびコンテンツの品質に関する懸念事項を検証します。

スコアラー

それは何を評価するのですか?

ガードレールハブ

ToxicLanguage

出力には、有害または攻撃的な言葉が含まれていますか?

リンク

NSFWText

出力には、職場閲覧注意(NSFW)または露骨な内容が含まれていますか?

リンク

DetectJailbreak

入力内容に脱獄(ジェイルブレイク)やプロンプトの注入試行が含まれていますか?

リンク

DetectPII

出力には個人を特定できる情報が含まれていますか?

リンク

SecretsPresent

出力にはAPIキー、トークン、またはその他の機密情報が含まれていますか?

リンク

GibberishText

出力に意味不明なテキストや支離滅裂なテキストが含まれていますか?

リンク

名前でスコアラーを作成する

バリデーター名を文字列として渡すことで、 get_scorerを使用してスコアラーを動的に作成できます。

Python
from mlflow.genai.scorers.guardrails import get_scorer

scorer = get_scorer(
validator_name="ToxicLanguage",
threshold=0.7,
)
feedback = scorer(
outputs="This is a professional response.",
)

構成

Guardrails AIスコアラーは、コンストラクターへのキーワード引数としてバリデーター固有の問題を受け入れます。

Python
from mlflow.genai.scorers.guardrails import ToxicLanguage, DetectPII, DetectJailbreak

# Toxicity detection with custom threshold
scorer = ToxicLanguage(
threshold=0.7,
validation_method="sentence",
)

# PII detection with custom entity types
pii_scorer = DetectPII(
pii_entities=["CREDIT_CARD", "SSN", "EMAIL_ADDRESS"],
)

# Jailbreak detection with custom sensitivity
jailbreak_scorer = DetectJailbreak(
threshold=0.9,
)

バリデーター固有の およびその他のバリデーターについては、 Guardrails AIドキュメントGuardrails Hub を参照してください。