---
title: "Manage Azure OpenAI content filtering in a .NET app"
description: "Learn how to manage Azure OpenAI content filtering programmatically in a .NET app using the Azure OpenAI client library."
ms.topic: how-to
ms.date: 03/04/2026
ai-usage: ai-assisted
---

# Work with Azure OpenAI content filtering in a .NET app

This article shows how to handle content filtering in a .NET app. Azure OpenAI Service includes a content filtering system that works alongside core models. It runs both the prompt and completion through an ensemble of classification models to detect and take action on specific categories of potentially harmful content in both input prompts and output completions. Variations in API configurations and application design might affect completions and thus filtering behavior.

For a deeper exploration of content filtering concepts and concerns, see the [Content Filtering](/azure/ai-services/openai/concepts/content-filter) documentation.

## Prerequisites

* An Azure account that has an active subscription. [Create an account for free](https://azure.microsoft.com/pricing/purchase-options/azure-account?cid=msft_learn).
* [.NET SDK](https://dotnet.microsoft.com/download/visual-studio-sdks)
* [Create and deploy an Azure OpenAI Service resource](/azure/ai-services/openai/how-to/create-resource)

## Configure and test the content filter

To use the sample code in this article, you need to create and assign a content filter to your OpenAI model.

1. [Create and assign a content filter](/azure/ai-services/openai/how-to/content-filters) to your provisioned model.

1. Add the [`Azure.AI.OpenAI`](https://www.nuget.org/packages/Azure.AI.OpenAI) NuGet package to your project.

   ```dotnetcli
   dotnet add package Azure.AI.OpenAI
   ```

   Or, in .NET 10+:

   ```dotnetcli
   dotnet package add Azure.AI.OpenAI
   ```

1. Create a simple chat completion flow in your .NET app using the `AzureOpenAiClient`. Replace the `YOUR_MODEL_ENDPOINT` and `YOUR_MODEL_DEPLOYMENT_NAME` values with your own.


1. Replace the `YOUR_PROMPT` placeholder with your own message and run the app to experiment with content filtering results. If you enter a prompt the AI considers unsafe, Azure OpenAI returns a `400 Bad Request` code. The app prints a message in the console similar to the following:

```output
The response was filtered due to the prompt triggering Azure OpenAI's content management policy...
```

## Related content

* [Create and assign a content filter](/azure/ai-services/openai/how-to/content-filters)
* [Content Filtering concepts](/azure/ai-services/openai/concepts/content-filter)
* [Create a chat app](../quickstarts/prompt-model.md)
