Quickstart: Detect protected material (preview)
The protected material text describes language that matches known text content (for example, song lyrics, articles, recipes, selected web content). This feature can be used to identify and block known text content from being displayed in language model output (English content only).
Prerequisites
- An Azure subscription - Create one for free
- Once you have your Azure subscription, create a Content Safety resource in the Azure portal to get your key and endpoint. Enter a unique name for your resource, select your subscription, and select a resource group, supported region (East US or West Europe), and supported pricing tier. Then select Create.
- The resource takes a few minutes to deploy. After it finishes, Select go to resource. In the left pane, under Resource Management, select Subscription Key and Endpoint. The endpoint and either of the keys are used to call APIs.
- cURL installed
Analyze text for protected material detection
The following section walks through a sample request with cURL. Paste the command below into a text editor, and make the following changes.
- Replace
<endpoint>
with the endpoint URL associated with your resource. - Replace
<your_subscription_key>
with one of the keys that come with your resource. - Optionally, replace the
"text"
field in the body with your own text you'd like to analyze.Tip
Text size and granularity
The default maximum length for text submissions is 1K characters. The minimum length is 111 characters. Protected material detection is meant to be run on LLM completions, not user prompts.
curl --location --request POST '<endpoint>/contentsafety/text:detectProtectedMaterial?api-version=2023-10-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your_subscription_key>' \
--header 'Content-Type: application/json' \
--data-raw '{
"text": "to everyone, the best things in life are free. the stars belong to everyone, they gleam there for you and me. the flowers in spring, the robins that sing, the sunbeams that shine, they\'re yours, they\'re mine. and love can come to everyone, the best things in life are"
}'
The below fields must be included in the url:
Name | Required | Description | Type |
---|---|---|---|
API Version | Required | This is the API version to be checked. The current version is: api-version=2023-10-15-preview. Example: <endpoint>/contentsafety/text:detectProtectedMaterial?api-version=2023-10-15-preview |
String |
The parameters in the request body are defined in this table:
Name | Required | Description | Type |
---|---|---|---|
text | Required | This is the raw text to be checked. Other non-ascii characters can be included. | String |
See the following sample request body:
{
"text": "string"
}
Open a command prompt window and run the cURL command.
Interpret the API response
You should see the protected material detection results displayed as JSON data in the console output. For example:
{
"protectedMaterialAnalysis": {
"detected": true
}
}
The JSON fields in the output are defined here:
Name | Description | Type |
---|---|---|
protectedMaterialAnalysis | Each output class that the API predicts. | String |
detected | Whether protected material was detected or not. | Boolean |
Clean up resources
If you want to clean up and remove an Azure AI services subscription, you can delete the resource or resource group. Deleting the resource group also deletes any other resources associated with it.
Next steps
Configure filters for each category and test on datasets using Content Safety Studio, export the code and deploy.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for