• メッセージ
  • マネージドエージェント
  • 管理

Search...
⌘K
ユースケース
概要チケットルーティングカスタマーサポートエージェントコンテンツモデレーション法務文書の要約
プロンプトエンジニアリング
概要プロンプトのベストプラクティスClaude Fable 5のプロンプトClaude Opus 4.8のプロンプトコンソールのプロンプトツール
テストと評価
成功の定義と評価の構築コンソールでの評価ツールの使用レイテンシの削減
ガードレールの強化
ハルシネーションの削減出力の一貫性の向上ジェイルブレイクの軽減プロンプトリークの削減
リファレンス
用語集

Log in
コンテンツモデレーション
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Solutions

  • AI agents
  • Code modernization
  • Coding
  • Customer support
  • Education
  • Financial services
  • Government
  • Life sciences

Partners

  • Claude on AWS
  • Google Cloud's Vertex AI

Learn

  • Blog
  • Courses
  • Use cases
  • Connectors
  • Customer stories
  • Engineering at Anthropic
  • Events
  • Powered by Claude
  • Service partners
  • Startups program

Company

  • Anthropic
  • Careers
  • Economic Futures
  • Research
  • News
  • Responsible Scaling Policy
  • Security and compliance
  • Transparency

Learn

  • Blog
  • Courses
  • Use cases
  • Connectors
  • Customer stories
  • Engineering at Anthropic
  • Events
  • Powered by Claude
  • Service partners
  • Startups program

Help and security

  • Availability
  • Status
  • Support
  • Discord

Terms and policies

  • Privacy policy
  • Responsible disclosure policy
  • Terms of service: Commercial
  • Terms of service: Consumer
  • Usage policy
ベストプラクティス/ユースケース

コンテンツモデレーション

コンテンツモデレーションは、デジタルアプリケーションにおいて安全で敬意に満ちた生産的な環境を維持するための重要な要素です。このガイドでは、Claudeを使用してデジタルアプリケーション内のコンテンツをモデレートする方法について説明します。

Claudeを使用したコンテンツモデレーション実装の例については、コンテンツモデレーションクックブックをご覧ください。


このガイドは、アプリケーション内のユーザー生成コンテンツのモデレーションに焦点を当てています。Claudeとのインタラクションのモデレーションに関するガイダンスをお探しの場合は、ガードレールガイドを参照してください。

Claudeで構築する前に

コンテンツモデレーションにClaudeを使用するかどうかを決定する

コンテンツモデレーションに従来のMLやルールベースのアプローチではなく、ClaudeのようなLLMを使用すべきであることを示す主な指標を以下に示します。


Anthropicは、すべてのClaudeモデルを正直で、有用で、無害であるようにトレーニングしています。これにより、使用されるプロンプトに関係なく、Claudeが特に危険とみなされるコンテンツ(利用規定に沿って)をモデレートする可能性があります。たとえば、ユーザーが露骨な性的コンテンツを投稿できるようにしたいアダルトウェブサイトは、プロンプトで露骨な性的コンテンツをモデレートしないように指定しても、Claudeが露骨なコンテンツをモデレーションが必要なものとしてフラグを立てる場合があります。モデレーションソリューションを構築する前に、利用規定を確認することをお勧めします。

モデレートするコンテンツの例を生成する

コンテンツモデレーションソリューションを開発する前に、まずフラグを立てるべきコンテンツとフラグを立てるべきでないコンテンツの例を作成します。コンテンツモデレーションシステムが効果的に処理するのが難しいエッジケースや困難なシナリオを必ず含めてください。その後、例を確認して、明確に定義されたモデレーションカテゴリのリストを作成します。 たとえば、ソーシャルメディアプラットフォームが生成する例には、次のようなものが含まれる場合があります。

allowed_user_comments = [
    "This movie was great, I really enjoyed it. The main actor really killed it!",
    "I hate Mondays.",
    "It is a great time to invest in gold!",
]

disallowed_user_comments = [
    "Delete this post now or you better hide. I am coming after you and your family.",
    "Stay away from the 5G cellphones!! They are using 5G to control you.",
    "Congratulations! You have won a $1,000 gift card. Click here to claim your prize!",
]

# コンテンツモデレーションをテストするためのサンプルユーザーコメント
user_comments = allowed_user_comments + disallowed_user_comments

# コンテンツモデレーションで安全でないと見なされるカテゴリのリスト
unsafe_categories = [
    "Child Exploitation",
    "Conspiracy Theories",
    "Hate",
    "Indiscriminate Weapons",
    "Intellectual Property",
    "Non-Violent Crimes",
    "Privacy",
    "Self-Harm",
    "Sex Crimes",
    "Sexual Content",
    "Specialized Advice",
    "Violent Crimes",
]

これらの例を効果的にモデレートするには、言語のニュアンスを理解する必要があります。コメントThis movie was great, I really enjoyed it. The main actor really killed it!では、コンテンツモデレーションシステムは「killed it」が比喩であり、実際の暴力を示すものではないことを認識する必要があります。逆に、暴力への明示的な言及がないにもかかわらず、コメントDelete this post now or you better hide. I am coming after you and your family.はコンテンツモデレーションシステムによってフラグが立てられるべきです。

unsafe_categoriesリストは、特定のニーズに合わせてカスタマイズできます。たとえば、未成年者がウェブサイトでコンテンツを作成するのを防ぎたい場合は、リストに「Underage Posting」を追加できます。


Claudeを使用してコンテンツをモデレートする方法

適切なClaudeモデルを選択する

モデルを選択する際には、データのサイズを考慮することが重要です。コストが懸念される場合、Claude Haiku 4.5のような小型モデルは、コスト効率の高さから優れた選択肢です。以下は、月間10億件の投稿を受け取るソーシャルメディアプラットフォームのテキストをモデレートするコストの見積もりです。

  • コンテンツサイズ

    • 月間投稿数:10億
    • 投稿あたりの文字数:100
    • 総文字数:1,000億
  • 推定トークン数

    • 入力トークン:286億(3.5文字あたり1トークンと仮定)
    • フラグが立てられたメッセージの割合:3%
    • フラグが立てられたメッセージあたりの出力トークン:50
    • 総出力トークン:15億
  • Claude Haiku 4.5の推定コスト

    • 入力トークンコスト:28,600 MTok * $1.00/MTok = $28,600 USD
    • 出力トークンコスト:1,500 MTok * $5.00/MTok = $7,500 USD
    • 月間コスト:$28,600 + $7,500 = $36,100 USD
  • Claude Opus 4.8の推定コスト

    • 入力トークンコスト:28,600 MTok * $5.00/MTok = $143,000 USD
    • 出力トークンコスト:1,500 MTok * $25.00/MTok = $37,500 USD
    • 月間コスト:$143,000 + $37,500 = $180,500 USD

実際のコストはこれらの見積もりと異なる場合があります。これらの見積もりは、バッチ処理のセクションで取り上げたプロンプトに基づいています。レスポンスからexplanationフィールドを削除することで、出力トークンをさらに削減できます。

強力なプロンプトを構築する

Claudeをコンテンツモデレーションに使用するには、Claudeがアプリケーションのモデレーション要件を理解する必要があります。まず、モデレーションのニーズを定義できるプロンプトを作成することから始めましょう。

Python
import json

# Anthropicクライアントを初期化します
client = anthropic.Anthropic()


def moderate_message(message, unsafe_categories):
    # 安全でないカテゴリのリストを、各カテゴリを改行で区切った文字列に変換します
    unsafe_category_str = "\n".join(unsafe_categories)

    # メッセージと安全でないカテゴリを含む、Claude向けのプロンプトを構築します
    assessment_prompt = f"""
    Determine whether the following message warrants moderation,
    based on the unsafe categories outlined below.

    Message:
    <message>{message}</message>

    Unsafe Categories:
    <categories>
    {unsafe_category_str}
    </categories>

    Respond with ONLY a JSON object, using the format below:
    {{
    "violation": <Boolean field denoting whether the message should be moderated>,
    "categories": [Comma-separated list of violated categories],
    "explanation": [Optional. Only include if there is a violation.]
    }}"""

    # コンテンツモデレーションのためにClaudeにリクエストを送信します
    response = client.messages.create(
        model="claude-haiku-4-5-20251001",  # Using the Haiku model for lower costs
        max_tokens=200,
        temperature=0,  # Use 0 temperature for increased consistency
        messages=[{"role": "user", "content": assessment_prompt}],
    )

    # ClaudeからのJSONレスポンスを解析します
    assessment = json.loads(response.content[0].text)

    # 評価結果から違反ステータスを抽出します
    contains_violation = assessment["violation"]

    # 違反がある場合はカテゴリと説明を取得し、それ以外の場合は空のデフォルト値を使用します
    violated_categories = assessment.get("categories", []) if contains_violation else []
    explanation = assessment.get("explanation") if contains_violation else None

    return contains_violation, violated_categories, explanation


# 各コメントを処理して結果を出力します
for comment in user_comments:
    print(f"\nComment: {comment}")
    violation, violated_categories, explanation = moderate_message(
        comment, unsafe_categories
    )

    if violation:
        print(f"Violated Categories: {', '.join(violated_categories)}")
        print(f"Explanation: {explanation}")
    else:
        print("No issues detected.")

この例では、moderate_message関数に、安全でないコンテンツカテゴリと評価するメッセージを含む評価プロンプトが含まれています。プロンプトは、上記で定義された安全でないカテゴリに基づいて、メッセージをモデレートすべきかどうかを評価するようClaudeに求めます。

次に、モデルの評価が解析され、違反があるかどうかが判断されます。違反がある場合、Claudeは違反したカテゴリのリストと、メッセージが安全でない理由の説明も返します。

プロンプトを評価する

コンテンツモデレーションは分類問題です。したがって、分類クックブックで概説されているのと同じ手法を使用して、コンテンツモデレーションシステムの精度を判断できます。

追加の考慮事項として、コンテンツモデレーションを二値分類問題として扱う代わりに、さまざまなリスクレベルを表す複数のカテゴリを作成することもできます。複数のリスクレベルを作成することで、モデレーションの積極性を調整できます。たとえば、高リスクとみなされるユーザークエリを自動的にブロックし、中リスクのクエリが多いユーザーには人間によるレビューのフラグを立てることができます。

Python
import json

# Anthropicクライアントを初期化します
client = anthropic.Anthropic()


def assess_risk_level(message, unsafe_categories):
    # 安全でないカテゴリのリストを、各カテゴリを改行で区切った文字列に変換します
    unsafe_category_str = "\n".join(unsafe_categories)

    # メッセージ、安全でないカテゴリ、リスクレベルの定義を含むClaude用のプロンプトを構築します
    assessment_prompt = f"""
    Assess the risk level of the following message,
    based on the unsafe categories listed below.

Message:
<message>{message}</message>

Unsafe Categories:
<categories>
{unsafe_category_str}
</categories>

Assign a risk level based on your confidence that the user's message should be moderated
based on the defined unsafe categories:

0 - No risk
1 - Low risk
2 - Medium risk
3 - High risk

Respond with ONLY a JSON object, using the format below:
{{
  "risk_level": <Numerical field denoting the risk level>,
  "categories": [Comma-separated list of violated categories],
  "explanation": <Optional. Only include if risk level is greater than 0>
}}"""

    # リスク評価のためにClaudeにリクエストを送信します
    response = client.messages.create(
        model="claude-haiku-4-5-20251001",  # Using the Haiku model for lower costs
        max_tokens=200,
        temperature=0,  # Use 0 temperature for increased consistency
        messages=[{"role": "user", "content": assessment_prompt}],
    )

    # ClaudeからのJSONレスポンスを解析します
    assessment = json.loads(response.content[0].text)

    # 評価結果からリスクレベル、違反したカテゴリ、説明を抽出します
    risk_level = assessment["risk_level"]
    violated_categories = assessment["categories"]
    explanation = assessment.get("explanation")

    return risk_level, violated_categories, explanation


# 各コメントを処理して結果を出力します
for comment in user_comments:
    print(f"\nComment: {comment}")
    risk_level, violated_categories, explanation = assess_risk_level(
        comment, unsafe_categories
    )

    print(f"Risk Level: {risk_level}")
    if violated_categories:
        print(f"Violated Categories: {', '.join(violated_categories)}")
    if explanation:
        print(f"Explanation: {explanation}")

このコードは、Claudeを使用してメッセージのリスクレベルを評価するassess_risk_level関数を実装しています。この関数は、メッセージと安全でないカテゴリのリストを入力として受け取ります。

関数内では、評価するメッセージ、安全でないカテゴリ、およびリスクレベルを評価するための具体的な指示を含むプロンプトがClaude用に生成されます。プロンプトは、リスクレベル、違反したカテゴリ、およびオプションの説明を含むJSONオブジェクトで応答するようClaudeに指示します。

このアプローチにより、リスクレベルを割り当てることで柔軟なコンテンツモデレーションが可能になります。評価されたリスクレベルに基づいてコンテンツフィルタリングを自動化したり、人間によるレビューのためにコメントにフラグを立てたりするために、より大きなシステムにシームレスに統合できます。たとえば、このコードを実行すると、コメントDelete this post now or you better hide. I am coming after you and your family.は危険な脅迫のため高リスクとして識別されます。逆に、コメントStay away from the 5G cellphones!! They are using 5G to control you.は中リスクとして分類されます。

プロンプトをデプロイする

ソリューションの品質に自信が持てたら、本番環境にデプロイする時です。本番環境でコンテンツモデレーションを使用する際に従うべきベストプラクティスを以下に示します。

  1. ユーザーに明確なフィードバックを提供する: ユーザー入力がブロックされたり、コンテンツモデレーションによってレスポンスにフラグが立てられたりした場合、ユーザーがメッセージにフラグが立てられた理由と、適切に言い換える方法を理解できるように、有益で建設的なフィードバックを提供します。前述のコーディング例では、これはClaudeレスポンスのexplanationフィールドを通じて行われます。

  2. モデレートされたコンテンツを分析する: モデレーションシステムによってフラグが立てられているコンテンツの種類を追跡し、傾向と改善の可能性がある領域を特定します。

  3. 継続的に評価および改善する: 適合率や再現率の追跡などの指標を使用して、コンテンツモデレーションシステムのパフォーマンスを定期的に評価します。このデータを使用して、モデレーションプロンプト、キーワード、評価基準を反復的に改善します。


パフォーマンスを向上させる

複雑なシナリオでは、標準的なプロンプトエンジニアリング手法を超えてパフォーマンスを向上させるための追加の戦略を検討することが役立つ場合があります。以下にいくつかの高度な戦略を示します。

トピックを定義し例を提供する

プロンプトに安全でないカテゴリをリストすることに加えて、各カテゴリに関連する定義とフレーズを提供することで、さらなる改善が可能です。

Python
import json

# Anthropicクライアントを初期化
client = anthropic.Anthropic()

# コンテンツモデレーションで安全でないとみなされるカテゴリとその定義の辞書
unsafe_category_definitions = {
    "Child Exploitation": "Content that depicts child nudity or that enables, encourages, excuses, or depicts the sexual abuse of children.",
    "Conspiracy Theories": """Content that promotes or endorses unfounded, false, or misleading theories about events, situations, or individuals,
        which can incite harm or undermine public trust in institutions or facts.""",
    "Hate": """Content that is hateful toward people on the basis of their protected characteristics
        (race, color, ethnicity, national origin, disability, religious affiliation, caste, sexual orientation, sex, gender identity and serious disease),
        or content that perpetuates negative stereotypes.""",
    "Indiscriminate Weapons": "Content that enables the creation of weapons of mass destruction.",
    "Intellectual Property": "Content that violates the intellectual property rights of third parties.",
    "Non-Violent Crimes": "Content that enables, encourages, or excuses the commission of non-violent crimes.",
    "Privacy": "Content that contains sensitive, personal information about private individuals.",
    "Self-Harm": "Content that enables, encourages, or excuses acts of intentional self-harm.",
    "Sex Crimes": "Content that enables, encourages, or excuses the commission of sex crimes.",
    "Sexual Content": "Content that contains erotic descriptions or explicit depictions of sex acts.",
    "Specialized Advice": """Content that contains financial, medical, or legal advice.
        Financial advice includes guidance on investments, stocks, bonds, or any financial planning.""",
    "Violent Crimes": "Content that enables, encourages, or excuses the commission of violent crimes.",
}


def moderate_message_with_definitions(message, unsafe_category_definitions):
    # 安全でないカテゴリの文字列をフォーマット(各カテゴリと定義を改行区切りで)
    unsafe_category_str = "\n".join(
        f"{category}: {definition}"
        for category, definition in unsafe_category_definitions.items()
    )

    # メッセージと安全でないカテゴリを含むClaude用のプロンプトを構築
    assessment_prompt = f"""Determine whether the following message warrants moderation, based on the unsafe categories outlined below.

Message:
<message>{message}</message>

Unsafe Categories and Their Definitions:
<categories>
{unsafe_category_str}
</categories>

It's important that you remember all unsafe categories and their definitions.

Respond with ONLY a JSON object, using the format below:
{{
  "violation": <Boolean field denoting whether the message should be moderated>,
  "categories": [Comma-separated list of violated categories],
  "explanation": [Optional. Only include if there is a violation.]
}}"""

    # コンテンツモデレーションのためにClaudeへリクエストを送信
    response = client.messages.create(
        model="claude-haiku-4-5-20251001",  # Using the Haiku model for lower costs
        max_tokens=200,
        temperature=0,  # Use 0 temperature for increased consistency
        messages=[{"role": "user", "content": assessment_prompt}],
    )

    # ClaudeからのJSONレスポンスを解析
    assessment = json.loads(response.content[0].text)

    # 評価結果から違反ステータスを抽出
    contains_violation = assessment["violation"]

    # 違反がある場合はカテゴリと説明を取得、なければ空のデフォルト値を使用
    violated_categories = assessment.get("categories", []) if contains_violation else []
    explanation = assessment.get("explanation") if contains_violation else None

    return contains_violation, violated_categories, explanation


# 各コメントを処理して結果を出力
for comment in user_comments:
    print(f"\nComment: {comment}")
    violation, violated_categories, explanation = moderate_message_with_definitions(
        comment, unsafe_category_definitions
    )

    if violation:
        print(f"Violated Categories: {', '.join(violated_categories)}")
        print(f"Explanation: {explanation}")
    else:
        print("No issues detected.")

moderate_message_with_definitions関数は、各安全でないカテゴリに詳細な定義を組み合わせることができるようにすることで、前述のmoderate_message関数を拡張しています。これは、元の関数のunsafe_categoriesリストをunsafe_category_definitions辞書に置き換えることでコード内で実現されます。この辞書は、各安全でないカテゴリを対応する定義にマッピングします。カテゴリ名とその定義の両方がプロンプトに含まれます。

特に、Specialized Adviceカテゴリの定義では、禁止すべき金融アドバイスの種類が指定されるようになりました。その結果、以前はmoderate_messageの評価を通過していたコメントIt is a great time to invest in gold!が、今では違反をトリガーします。

バッチ処理を検討する

リアルタイムのモデレーションが必要ない状況でコストを削減するには、メッセージをバッチでモデレートすることを検討してください。プロンプトのコンテキスト内に複数のメッセージを含め、どのメッセージをモデレートすべきかを評価するようClaudeに依頼します。

Python
import json

# Anthropicクライアントを初期化
client = anthropic.Anthropic()


def batch_moderate_messages(messages, unsafe_categories):
    # 安全でないカテゴリのリストを文字列に変換(各カテゴリを改行で区切る)
    unsafe_category_str = "\n".join(unsafe_categories)

    # メッセージ文字列をフォーマット(各メッセージをXML風タグで囲みIDを付与)
    messages_str = "\n".join(
        [f"<message id={idx}>{msg}</message>" for idx, msg in enumerate(messages)]
    )

    # メッセージと安全でないカテゴリを含むClaude用プロンプトを構築
    assessment_prompt = f"""Determine the messages to moderate, based on the unsafe categories outlined below.

Messages:
<messages>
{messages_str}
</messages>

Unsafe Categories:
<categories>
{unsafe_category_str}
</categories>

Respond with ONLY a JSON object, using the format below:
{{
  "violations": [
    {{
      "id": <message id>,
      "categories": [list of violated categories],
      "explanation": <Explanation of why there's a violation>
    }},
    ...
  ]
}}

Important Notes:
- Remember to analyze every message for a violation.
- Select any number of violations that reasonably apply."""

    # コンテンツモデレーションのためにClaudeへリクエストを送信
    response = client.messages.create(
        model="claude-haiku-4-5-20251001",  # Using the Haiku model for lower costs
        max_tokens=2048,  # Increased max token count to handle batches
        temperature=0,  # Use 0 temperature for increased consistency
        messages=[{"role": "user", "content": assessment_prompt}],
    )

    # ClaudeからのJSONレスポンスを解析
    assessment = json.loads(response.content[0].text)
    return assessment


# コメントのバッチを処理してレスポンスを取得
response_obj = batch_moderate_messages(user_comments, unsafe_categories)

# 検出された各違反の結果を出力
for violation in response_obj["violations"]:
    print(f"""Comment: {user_comments[violation["id"]]}
Violated Categories: {", ".join(violation["categories"])}
Explanation: {violation["explanation"]}
""")

この例では、batch_moderate_messages関数が単一のClaude API呼び出しでメッセージのバッチ全体のモデレーションを処理します。 関数内では、評価するメッセージのリストと安全でないコンテンツカテゴリを含むプロンプトが作成されます。プロンプトは、違反を含むすべてのメッセージをリストしたJSONオブジェクトを返すようClaudeに指示します。レスポンス内の各メッセージは、入力リスト内のメッセージの位置に対応するidによって識別されます。 特定のニーズに最適なバッチサイズを見つけるには、ある程度の実験が必要になる場合があることに注意してください。バッチサイズが大きいほどコストを削減できますが、品質がわずかに低下する可能性もあります。さらに、より長いレスポンスに対応するために、Claude API呼び出しのmax_tokensパラメータを増やす必要がある場合があります。選択したモデルが出力できるトークンの最大数の詳細については、モデル比較表を参照してください。


コンテンツモデレーションクックブック


Claudeをコンテンツモデレーションに使用する方法の完全に実装されたコードベースの例をご覧ください。


ガードレールガイド

Claudeとのインタラクションをモデレートするための手法については、ガードレールガイドをご覧ください。

Was this page helpful?

  • Claudeで構築する前に
  • コンテンツモデレーションにClaudeを使用するかどうかを決定する
  • モデレートするコンテンツの例を生成する
  • Claudeを使用してコンテンツをモデレートする方法
  • 適切なClaudeモデルを選択する
  • 強力なプロンプトを構築する
  • プロンプトを評価する
  • プロンプトをデプロイする
  • パフォーマンスを向上させる
  • トピックを定義し例を提供する
  • バッチ処理を検討する