# 生成AIのモデレーション

> 生成AIのモデレーション - DataRobot
> Pythonクライアントを使用して、モデレーションテンプレートの一覧表示、設定の作成、および安全ではない生成AIプロンプトや回答のフィルターを行います。

This Markdown file sits beside the HTML page at the same path (with a `.md` suffix). It summarizes the topic and lists links for tools and LLM context.

Companion generated at `2026-07-30T11:40:01.287413+00:00` (UTC).

## Primary page

- [生成AIのモデレーション](https://docs.datarobot.com/ja/docs/api/dev-learning/python/genai/moderation.html.md): Full documentation for this topic (Markdown sidecar).

## Sections on this page

- [モデレーションテンプレートのリスト](https://docs.datarobot.com/ja/docs/api/dev-learning/python/genai/moderation.html.md#list-moderation-templates): In-page section heading.
- [モデレーション設定の作成](https://docs.datarobot.com/ja/docs/api/dev-learning/python/genai/moderation.html.md#create-a-moderation-configuration): In-page section heading.
- [モデレーション設定のリスト](https://docs.datarobot.com/ja/docs/api/dev-learning/python/genai/moderation.html.md#list-moderation-configurations): In-page section heading.
- [モデレーション設定の取得](https://docs.datarobot.com/ja/docs/api/dev-learning/python/genai/moderation.html.md#get-a-moderation-configuration): In-page section heading.
- [モデレーション設定の更新](https://docs.datarobot.com/ja/docs/api/dev-learning/python/genai/moderation.html.md#update-moderation-configuration): In-page section heading.
- [全体的なモデレーション設定の取得](https://docs.datarobot.com/ja/docs/api/dev-learning/python/genai/moderation.html.md#get-the-overall-moderation-configuration): In-page section heading.
- [全体的なモデレーション設定のリスト](https://docs.datarobot.com/ja/docs/api/dev-learning/python/genai/moderation.html.md#list-the-overall-moderation-configurations): In-page section heading.
- [全体的なモデレーション設定の更新](https://docs.datarobot.com/ja/docs/api/dev-learning/python/genai/moderation.html.md#update-the-overall-moderation-configuration): In-page section heading.

## Documentation content

[モデレーション設定](https://docs.datarobot.com/ja/docs/api/reference/sdk/gen-moderation.html.md#datarobot.models.moderation.configuration.ModerationConfiguration) は、プロンプトと回答をフィルターすることで、生成AIアプリケーションが安全で適切なコンテンツを生成するようにします。 モデレーションは、生成プロセスのさまざまな段階で、問題のあるコンテンツをブロックしたり、警告を表示したりできます。

## モデレーションテンプレートのリスト

利用可能なすべてのモデレーションテンプレートを取得するには：

```
import datarobot as dr
templates = dr.ModerationTemplate.list()
for template in templates:
    print(f"Template: {template.name}")
    print(f"  Description: {template.description}") 
```

## モデレーション設定の作成

テンプレートからモデレーション設定を作成します。 モデレーション設定を作成する際は、以下を指定する必要があります。

- template_id ：この設定のベースとなるテンプレートのID。
- name ：設定のわかりやすい名前。
- description ：設定の説明。
- stages ：このガードが有効なモデレーションのステージ（例：PROMPT、RESPONSE）。
- entity_id ：この設定が適用されるカスタムモデルバージョンまたはプレイグラウンドのID。
- entity_type ：関連付けられたエンティティのタイプ（CUSTOM_MODEL_VERSIONまたはPLAYGROUND）。
- intervention ：モデレーションに失敗した場合に実行するアクション（BLOCKまたはWARN）。
- llm_type ：このガードが使用する基盤LLM。

```
templates = dr.ModerationTemplate.list()
template = templates[0]
custom_model_version = dr.CustomModelVersion.get(version_id)
moderation_config = dr.ModerationConfiguration.create(
    template_id=template.id,
    name="Content Safety Guard",
    description="Filters inappropriate content",
    stages=[dr.ModerationGuardStage.PROMPT, dr.ModerationGuardStage.RESPONSE],
    entity_id=custom_model_version.id,
    entity_type=dr.ModerationGuardEntityType.CUSTOM_MODEL_VERSION,
    intervention=dr.ModerationIntervention.BLOCK,
    llm_type=dr.ModerationGuardLlmType.DATAROBOT_LLM
)
moderation_config 
```

プレイグラウンドのモデレーションを作成することもできます。

```
playground = dr.genai.Playground.get(playground_id)
moderation_config = dr.ModerationConfiguration.create(
    template_id=template.id,
    name="Playground Safety Guard",
    description="Filters content in playground",
    stages=[dr.ModerationGuardStage.PROMPT, dr.ModerationGuardStage.RESPONSE],
    entity_id=playground.id,
    entity_type=dr.ModerationGuardEntityType.PLAYGROUND,
    intervention=dr.ModerationIntervention.WARN,
    llm_type=dr.ModerationGuardLlmType.DATAROBOT_LLM
) 
```

## モデレーション設定のリスト

エンティティの設定を取得するには：

```
custom_model_version = dr.CustomModelVersion.get(version_id)
configs = dr.ModerationConfiguration.list(
    entity_id=custom_model_version.id,
    entity_type=dr.ModerationGuardEntityType.CUSTOM_MODEL_VERSION
)
for config in configs:
    print(f"Config: {config.name}")
    print(f"  Stages: {config.stages}")
    print(f"  Intervention: {config.intervention}") 
```

## モデレーション設定の取得

特定の設定を取得するには：

```
config = dr.ModerationConfiguration.get(config_id)
print(f"Name: {config.name}")
print(f"Description: {config.description}")
print(f"Stages: {config.stages}") 
```

## モデレーション設定の更新

モデレーション設定を更新するには：

```
config = dr.ModerationConfiguration.get(config_id)
config.update(
    name="Updated Safety Guard",
    description="Enhanced content filtering",
    intervention=dr.ModerationIntervention.WARN
) 
```

## 全体的なモデレーション設定の取得

エンティティの全体的なモデレーション設定を取得します。

```
custom_model_version = dr.CustomModelVersion.get(version_id)
overall_config = dr.OverallModerationConfig.get(
    entity_id=custom_model_version.id,
    entity_type=dr.ModerationGuardEntityType.CUSTOM_MODEL_VERSION
)
if overall_config:
    print(f"Moderation enabled: {overall_config.is_enabled}")
    print(f"Configurations: {len(overall_config.configurations)}") 
```

## 全体的なモデレーション設定のリスト

すべての全体的なモデレーション設定を取得するには：

```
overall_configs = dr.OverallModerationConfig.list()
for config in overall_configs:
    print(f"Entity: {config.entity_id}")
    print(f"  Enabled: {config.is_enabled}") 
```

## 全体的なモデレーション設定の更新

全体的なモデレーション設定を変更するには：

```
overall_config = dr.OverallModerationConfig.get(
    entity_id=custom_model_version.id,
    entity_type=dr.ModerationGuardEntityType.CUSTOM_MODEL_VERSION
)
overall_config.update(is_enabled=True) 
```
