適用対象:Foundry (クラシック) ポータル。 この記事は、新しい Foundry ポータルでは使用できません。
新しいポータルの詳細を確認します。
メモ
この記事のリンクは、現在表示している Foundry (クラシック) ドキュメントではなく、新しい Microsoft Foundry ドキュメントのコンテンツを開く場合があります。
重要
Azure AI 推論ベータ SDK は非推奨となり、2026 年 8 月 26 日に廃止されます。 安定した OpenAI SDK を使用して、一般公開されている OpenAI/v1 API に切り替えます。 好みのプログラミング言語に SDK を使用して、 移行ガイド に従って OpenAI/v1 に切り替えます。
Microsoft Foundry に統合されたコンテンツ フィルタリング システムは、Foundry モデルと共に実行されます。 多クラス分類モデルのアンサンブルを使用して、4 つの重大度レベル (安全、低、中、高) で有害なコンテンツ (暴力、ヘイト、性的、自傷) の 4 つのカテゴリを検出します。 これは、パブリック リポジトリ内の脱獄リスク、既存のテキスト、およびコードを検出するためのオプションのバイナリ分類子を提供します。 コンテンツ カテゴリ、重大度レベル、およびコンテンツ フィルタリング システムの動作の詳細については、 次の記事を参照してください。
既定のコンテンツ フィルター構成では、プロンプトと完了の両方について、4 つの有害なカテゴリすべてについて、重大度が中程度のしきい値のコンテンツがフィルター処理されます。 重大度レベルが中または高で検出されたコンテンツは除外されますが、低または安全な重大度レベルで検出されたコンテンツはフィルター処理されません。
リソース レベルでコンテンツ フィルターを構成し、1 つ以上のデプロイに関連付けることができます。
前提 条件
この記事を完了するには、次のものが必要です。
Azure サブスクリプション。 GitHub モデルを使用している場合は、エクスペリエンスをアップグレードし、プロセスでAzureサブスクリプションを作成できます。 GitHubモデルからFoundryにアップグレードを読む。
Foundry リソース (旧称 Azure AI Services リソース)。 詳細については、「 Foundry リソースの作成」を参照してください。
- Foundry Tools リソースに接続されている AI プロジェクト。 Foundry で Microsoft Foundry Models サービスを構成するという手順をプロジェクト内で従うことができます。
カスタム コンテンツ フィルターを作成する
カスタム コンテンツ フィルターを作成するには、次の手順に従います。
Foundry ポータルに移動します。
左側のウィンドウから [ガードレールとコントロール ] を選択します。
[ コンテンツ フィルター ] タブを選択し、[ コンテンツ フィルターの作成] を選択します。
[ 基本情報 ] ページで、コンテンツ フィルターの名前を入力します。
[ 接続] で、プロジェクトに接続されている Foundry Tools リソースへの接続を選択します。
[ 次へ ] を選択して、[ 入力フィルター ] ページに移動します。
要件に応じて入力フィルターを構成します。 この構成は、要求がモデル自体に到達する前に適用されます。
[ 次へ ] を選択して 、[出力フィルター ] ページに移動します。
要件に応じて出力フィルターを構成します。 この構成は、モデルの実行後に適用され、コンテンツが生成されます。
[ 次へ ] を選択して [ 接続 ] ページに移動します。
このページでは、モデルのデプロイを作成されたコンテンツ フィルターに関連付けるオプションがあります。 関連付けられているモデルのデプロイはいつでも変更できます。
[ 次へ ] を選択して、フィルター設定を確認します。 次に、[ フィルターの作成] を選択します。
デプロイが完了すると、新しいコンテンツ フィルターがモデルのデプロイに適用されます。
コードにコンテンツフィルタリングを考慮する
モデル デプロイにコンテンツ フィルターを適用すると、サービスは入力と出力に基づいて要求をインターセプトできます。 コンテンツ フィルターがトリガーされると、エラーをトリガーしたルールの説明を含む 400 エラー コードが返されます。
pip のように、パッケージ マネージャーを使用してパッケージ azure-ai-inference をインストールします。
pip install azure-ai-inference
その後、パッケージを使用してモデルを使用できます。 次の例は、チャットの完了を処理するためのクライアントを作成する方法を示しています。
import os
from azure.ai.inference import ChatCompletionsClient
from azure.core.credentials import AzureKeyCredential
client = ChatCompletionsClient(
endpoint="https://<resource>.services.ai.azure.com/models",
credential=AzureKeyCredential(os.environ["AZURE_INFERENCE_CREDENTIAL"]),
)
サンプルを確認し、API リファレンス ドキュメントを読んで、作業を開始してください。
次の例は、Guardrails とコントロールをトリガーしたチャット完了要求の応答を示しています。
from azure.ai.inference.models import AssistantMessage, UserMessage, SystemMessage
from azure.core.exceptions import HttpResponseError
try:
response = model.complete(
messages=[
SystemMessage(content="You are an AI assistant that helps people find information."),
UserMessage(content="Chopping tomatoes and cutting them into cubes or wedges are great ways to practice your knife skills."),
]
)
print(response.choices[0].message.content)
except HttpResponseError as ex:
if ex.status_code == 400:
response = json.loads(ex.response._content.decode('utf-8'))
if isinstance(response, dict) and "error" in response:
print(f"Your request triggered an {response['error']['code']} error:\n\t {response['error']['message']}")
else:
raise ex
else:
raise ex
ベスト プラクティスに従う
特定のモデル、アプリケーション、展開シナリオに関連する潜在的な損害に対処するには、反復的な識別プロセス (赤いチーム テスト、ストレス テスト、分析など) と測定プロセスを使用して、コンテンツ フィルタリングの構成の決定を通知します。 コンテンツ フィルタリングなどの軽減策を実装したら、測定を繰り返して有効性をテストします。
Microsoft Foundry に統合されたコンテンツ フィルタリング システムは、Foundry モデルと共に実行されます。 多クラス分類モデルのアンサンブルを使用して、4 つの重大度レベル (安全、低、中、高) で有害なコンテンツ (暴力、ヘイト、性的、自傷) の 4 つのカテゴリを検出します。 これは、パブリック リポジトリ内の脱獄リスク、既存のテキスト、およびコードを検出するためのオプションのバイナリ分類子を提供します。 コンテンツ カテゴリ、重大度レベル、およびコンテンツ フィルタリング システムの動作の詳細については、 次の記事を参照してください。
既定のコンテンツ フィルター構成では、プロンプトと完了の両方について、4 つの有害なカテゴリすべてについて、重大度が中程度のしきい値のコンテンツがフィルター処理されます。 重大度レベルが中または高で検出されたコンテンツは除外されますが、低または安全な重大度レベルで検出されたコンテンツはフィルター処理されません。
リソース レベルでコンテンツ フィルターを構成し、1 つ以上のデプロイに関連付けることができます。
前提 条件
この記事を完了するには、次のものが必要です。
Azure サブスクリプション。 GitHub モデルを使用している場合は、エクスペリエンスをアップグレードし、プロセスでAzureサブスクリプションを作成できます。 GitHubモデルからFoundryにアップグレードを読む。
Foundry リソース (旧称 Azure AI Services リソース)。 詳細については、「 Foundry リソースの作成」を参照してください。
カスタム コンテンツ フィルタリングを使用してモデルのデプロイを追加する
Microsoft Foundry ポータルを使用するか、Bicepを使用してコードでコンテンツ フィルターを作成することをお勧めします。 カスタム コンテンツ フィルターの作成やデプロイへの適用は、Azure CLIを使用してサポートされていません。
コードにコンテンツフィルタリングを考慮する
モデル デプロイにコンテンツ フィルターを適用すると、サービスは入力と出力に基づいて要求をインターセプトできます。 コンテンツ フィルターがトリガーされると、エラーをトリガーしたルールの説明を含む 400 エラー コードが返されます。
pip のように、パッケージ マネージャーを使用してパッケージ azure-ai-inference をインストールします。
pip install azure-ai-inference
その後、パッケージを使用してモデルを使用できます。 次の例は、チャットの完了を処理するためのクライアントを作成する方法を示しています。
import os
from azure.ai.inference import ChatCompletionsClient
from azure.core.credentials import AzureKeyCredential
client = ChatCompletionsClient(
endpoint="https://<resource>.services.ai.azure.com/models",
credential=AzureKeyCredential(os.environ["AZURE_INFERENCE_CREDENTIAL"]),
)
サンプルを確認し、API リファレンス ドキュメントを読んで、作業を開始してください。
次の例は、Guardrails とコントロールをトリガーしたチャット完了要求の応答を示しています。
from azure.ai.inference.models import AssistantMessage, UserMessage, SystemMessage
from azure.core.exceptions import HttpResponseError
try:
response = model.complete(
messages=[
SystemMessage(content="You are an AI assistant that helps people find information."),
UserMessage(content="Chopping tomatoes and cutting them into cubes or wedges are great ways to practice your knife skills."),
]
)
print(response.choices[0].message.content)
except HttpResponseError as ex:
if ex.status_code == 400:
response = json.loads(ex.response._content.decode('utf-8'))
if isinstance(response, dict) and "error" in response:
print(f"Your request triggered an {response['error']['code']} error:\n\t {response['error']['message']}")
else:
raise ex
else:
raise ex
ベスト プラクティスに従う
特定のモデル、アプリケーション、展開シナリオに関連する潜在的な損害に対処するには、反復的な識別プロセス (赤いチーム テスト、ストレス テスト、分析など) と測定プロセスを使用して、コンテンツ フィルタリングの構成の決定を通知します。 コンテンツ フィルタリングなどの軽減策を実装したら、測定を繰り返して有効性をテストします。
Microsoft Foundry に統合されたコンテンツ フィルタリング システムは、Foundry モデルと共に実行されます。 多クラス分類モデルのアンサンブルを使用して、4 つの重大度レベル (安全、低、中、高) で有害なコンテンツ (暴力、ヘイト、性的、自傷) の 4 つのカテゴリを検出します。 これは、パブリック リポジトリ内の脱獄リスク、既存のテキスト、およびコードを検出するためのオプションのバイナリ分類子を提供します。 コンテンツ カテゴリ、重大度レベル、およびコンテンツ フィルタリング システムの動作の詳細については、 次の記事を参照してください。
既定のコンテンツ フィルター構成では、プロンプトと完了の両方について、4 つの有害なカテゴリすべてについて、重大度が中程度のしきい値のコンテンツがフィルター処理されます。 重大度レベルが中または高で検出されたコンテンツは除外されますが、低または安全な重大度レベルで検出されたコンテンツはフィルター処理されません。
リソース レベルでコンテンツ フィルターを構成し、1 つ以上のデプロイに関連付けることができます。
前提 条件
この記事を完了するには、次のものが必要です。
Azure サブスクリプション。 GitHub モデルを使用している場合は、エクスペリエンスをアップグレードし、プロセスでAzureサブスクリプションを作成できます。 GitHubモデルからFoundryへのアップグレードを読む。
Foundry リソース (旧称 Azure AI Services リソース)。 詳細については、「 Foundry リソースの作成」を参照してください。
Azure CLIをインストールします。
次の情報を特定します。
Azure サブスクリプション ID。
Foundry Tools リソース名。
Foundry Tools リソースをデプロイしたリソース グループ。
デプロイするモデル名、プロバイダー、バージョン、SKU。 Microsoft Foundry ポータルまたはAzure CLIを使用して、この情報を見つけることができます。 この例では、次のモデルをデプロイします。
-
モデル名::
Phi-4-mini-instruct -
Provider:
Microsoft -
バージョン:
1 - 展開の種類: グローバル標準
-
モデル名::
カスタム コンテンツ フィルタリングを使用してモデルのデプロイを追加する
テンプレート
ai-services-content-filter-template.bicepを使用して、コンテンツ フィルター ポリシーを記述します。ai-services-content-filter-template.bicep
@description('Name of the Azure AI Services account where the policy will be created') param accountName string @description('Name of the policy to be created') param policyName string @allowed(['Asynchronous_filter', 'Blocking', 'Default', 'Deferred']) param mode string = 'Default' @description('Base policy to be used for the new policy') param basePolicyName string = 'Microsoft.DefaultV2' param contentFilters array = [ { name: 'Violence' severityThreshold: 'Medium' blocking: true enabled: true source: 'Prompt' } { name: 'Hate' severityThreshold: 'Medium' blocking: true enabled: true source: 'Prompt' } { name: 'Sexual' severityThreshold: 'Medium' blocking: true enabled: true source: 'Prompt' } { name: 'Selfharm' severityThreshold: 'Medium' blocking: true enabled: true source: 'Prompt' } { name: 'Jailbreak' blocking: true enabled: true source: 'Prompt' } { name: 'Indirect Attack' blocking: true enabled: true source: 'Prompt' } { name: 'Profanity' blocking: true enabled: true source: 'Prompt' } { name: 'Violence' severityThreshold: 'Medium' blocking: true enabled: true source: 'Completion' } { name: 'Hate' severityThreshold: 'Medium' blocking: true enabled: true source: 'Completion' } { name: 'Sexual' severityThreshold: 'Medium' blocking: true enabled: true source: 'Completion' } { name: 'Selfharm' severityThreshold: 'Medium' blocking: true enabled: true source: 'Completion' } { name: 'Protected Material Text' blocking: true enabled: true source: 'Completion' } { name: 'Protected Material Code' blocking: false enabled: true source: 'Completion' } { name: 'Profanity' blocking: true enabled: true source: 'Completion' } ] resource raiPolicy 'Microsoft.CognitiveServices/accounts/raiPolicies@2024-06-01-preview' = { name: '${accountName}/${policyName}' properties: { mode: mode basePolicyName: basePolicyName contentFilters: contentFilters } }テンプレート
ai-services-deployment-template.bicepを使用して、モデルのデプロイについて説明します。ai-services-deployment-template.bicep
@description('Name of the Azure AI services account') param accountName string @description('Name of the model to deploy') param modelName string @description('Version of the model to deploy') param modelVersion string @allowed([ 'AI21 Labs' 'Cohere' 'Core42' 'DeepSeek' 'xAI' 'Meta' 'Microsoft' 'Mistral AI' 'OpenAI' ]) @description('Model provider') param modelPublisherFormat string @allowed([ 'GlobalStandard' 'DataZoneStandard' 'Standard' 'GlobalProvisioned' 'Provisioned' ]) @description('Model deployment SKU name') param skuName string = 'GlobalStandard' @description('Content filter policy name') param contentFilterPolicyName string = 'Microsoft.DefaultV2' @description('Model deployment capacity') param capacity int = 1 resource modelDeployment 'Microsoft.CognitiveServices/accounts/deployments@2024-04-01-preview' = { name: '${accountName}/${modelName}' sku: { name: skuName capacity: capacity } properties: { model: { format: modelPublisherFormat name: modelName version: modelVersion } raiPolicyName: contentFilterPolicyName == null ? 'Microsoft.Nill' : contentFilterPolicyName } }メインのデプロイ定義を作成します。
main.bicep
param accountName string param modelName string param modelVersion string param modelPublisherFormat string param contentFilterPolicyName string module raiPolicy 'ai-services-content-filter-template.bicep' = { name: 'raiPolicy' scope: resourceGroup(resourceGroupName) params: { accountName: accountName policyName: contentFilterPolicyName } } module modelDeployment 'ai-services-deployment-template.bicep' = { name: 'modelDeployment' scope: resourceGroup(resourceGroupName) params: { accountName: accountName modelName: modelName modelVersion: modelVersion modelPublisherFormat: modelPublisherFormat contentFilterPolicyName: contentFilterPolicyName } dependsOn: [ raiPolicy ] }デプロイを実行します。
RESOURCE_GROUP="<resource-group-name>" ACCOUNT_NAME="<azure-ai-model-inference-name>" MODEL_NAME="Phi-4-mini-instruct" PROVIDER="Microsoft" VERSION=1 RAI_POLICY_NAME="custom-policy" az deployment group create \ --resource-group $RESOURCE_GROUP \ --template-file main.bicep \ --parameters accountName=$ACCOUNT_NAME raiPolicyName=$RAI_POLICY_NAME modelName=$MODEL_NAME modelVersion=$VERSION modelPublisherFormat=$PROVIDER
コード内でコンテンツフィルタリングを考慮すること
モデル デプロイにコンテンツ フィルターを適用すると、サービスは入力と出力に基づいて要求をインターセプトできます。 コンテンツ フィルターがトリガーされると、エラーをトリガーしたルールの説明を含む 400 エラー コードが返されます。
pip のように、パッケージ マネージャーを使用してパッケージ azure-ai-inference をインストールします。
pip install azure-ai-inference
その後、パッケージを使用してモデルを使用できます。 次の例は、チャットの完了を処理するためのクライアントを作成する方法を示しています。
import os
from azure.ai.inference import ChatCompletionsClient
from azure.core.credentials import AzureKeyCredential
client = ChatCompletionsClient(
endpoint="https://<resource>.services.ai.azure.com/models",
credential=AzureKeyCredential(os.environ["AZURE_INFERENCE_CREDENTIAL"]),
)
サンプルを確認し、API リファレンス ドキュメントを読んで、作業を開始してください。
次の例は、Guardrails とコントロールをトリガーしたチャット完了要求の応答を示しています。
from azure.ai.inference.models import AssistantMessage, UserMessage, SystemMessage
from azure.core.exceptions import HttpResponseError
try:
response = model.complete(
messages=[
SystemMessage(content="You are an AI assistant that helps people find information."),
UserMessage(content="Chopping tomatoes and cutting them into cubes or wedges are great ways to practice your knife skills."),
]
)
print(response.choices[0].message.content)
except HttpResponseError as ex:
if ex.status_code == 400:
response = json.loads(ex.response._content.decode('utf-8'))
if isinstance(response, dict) and "error" in response:
print(f"Your request triggered an {response['error']['code']} error:\n\t {response['error']['message']}")
else:
raise ex
else:
raise ex
ベスト プラクティスに従う
特定のモデル、アプリケーション、展開シナリオに関連する潜在的な損害に対処するには、反復的な識別プロセス (赤いチーム テスト、ストレス テスト、分析など) と測定プロセスを使用して、コンテンツ フィルタリングの構成の決定を通知します。 コンテンツ フィルタリングなどの軽減策を実装したら、測定を繰り返して有効性をテストします。