Official agent skill

Azure AI Contentsafety Py

by microsoft in microsoft/skills

Azure AI Content Safety SDK for Python. An agent skill from microsoft/skills.

OfficialMITAuto-check passedDevOps & Cloud

Install Azure AI Contentsafety Py

skills CLI
$ npx skills add microsoft/skills --skill azure-ai-contentsafety-py -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install microsoft/skills azure-ai-contentsafety-py --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/microsoft/skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.github/plugins/azure-sdk-python/skills/azure-ai-contentsafety-py .claude/skills/azure-ai-contentsafety-py && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
azure-ai-contentsafety-py
GitHub stars
3.1k
Used in
5 other repos
Token cost
~2.2k tokens
SKILL.md length
439 words
Files
3 (incl. references)
Skills in repo
150
Repo updated
First seen
Licence
MIT

At a glance

Azure AI Content Safety SDK for Python. An agent skill from microsoft/skills.

  • Works in 9 steps: Pick sync OR async and stay consistent.… → Always use context managers for clients… → Use blocklists for domain-specific terms → …
  • Detecting harmful content in text and images with multi-severity classification
  • SKILL.md covers Installation, Environment Variables, Authentication & Lifecycle and Analyze Text, plus 8 more sections
  • Calls pip; reaches learn.microsoft.com; needs AZURE_TOKEN_CREDENTIALS and CONTENT_SAFETY_KEY

What it does

Azure AI Contentsafety Py is an agent skill from microsoft/skills, published by the product's own GitHub organization. Azure AI Content Safety SDK for Python. Use for detecting harmful content in text and images with multi-severity classification. Triggers: "azure-ai-contentsafety", "ContentSafetyClient", "content moderation", "harmful content", "text analysis", "image analysis".

Its SKILL.md is about 2.2k tokens, which your agent loads only when the skill is triggered. The skill folder holds 3 other files, including reference files (for example `references/capabilities.md` and `references/non-hero-scenarios.md`).

It sits in DevOps & Cloud, covering LLM guardrails. It works with Microsoft Azure, Azure AI Content Safety, Python and Visual Studio Code. The repository describes itself as: Skills, MCP servers, Custom Agents, Agents.md for SDKs to ground Coding Agents. The licence is MIT.

When your agent uses it

  • Detecting harmful content in text and images with multi-severity classification
  • Tasks that involve LLM guardrails

Example prompts

  • “azure-ai-contentsafety”
  • “ContentSafetyClient”
  • “content moderation”
  • “/azure-ai-contentsafety-py”

Requirements

  • Python 3
  • A credential in CONTENT_SAFETY_KEY

Workflow steps

9 steps, taken from the first numbered list in SKILL.md.

  1. Pick sync OR async and stay consistent. Do not mix azure.ai.contentsafety sync clients with azure.ai.contentsafety.aio async clients in…
  2. Always use context managers for clients and async credentials. Wrap every client in with ContentSafetyClient(...) as client: (sync) or…
  3. Use blocklists for domain-specific terms
  4. Set severity thresholds appropriate for your use case
  5. Handle multiple categories — content can be harmful in multiple ways
  6. Use halt_on_blocklist_hit for immediate rejection
  7. Log analysis results for audit and improvement
  8. Consider 8-severity mode for finer-grained control
  9. Pre-moderate AI outputs before showing to users

What it can do on your machine

Read from SKILL.md and the folder at commit d5741a1. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • pip

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Hosts in commands or code, which the agent is likely to contact:

    • learn.microsoft.com

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names these keys or tokens, usually read from environment variables:

    • AZURE_TOKEN_CREDENTIALS
    • CONTENT_SAFETY_KEY

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Azure AI Contentsafety Py loads about 2.2k tokens when it runs, and up to ~2.8k if it reads all its reference files. Until then it costs about 72 tokens; SKILL.md has 439 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~72
When it runs · the whole SKILL.md, loaded when a task matches
~2.2k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~2.8k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from microsoft/skills at commit d5741a1, republished under its MIT licence (© microsoft). 439 words, ~2,246 tokens.

Download SKILL.mdSave it as .claude/skills/azure-ai-contentsafety-py/SKILL.md (or your agent's skills folder). This skill also uses 2 other files; get the full folder from GitHub.
name
azure-ai-contentsafety-py
description
Azure AI Content Safety SDK for Python. Use for detecting harmful content in text and images with multi-severity classification. Triggers: "azure-ai-contentsafety", "ContentSafetyClient", "content moderation", "harmful content", "text analysis", "image analysis".
license
MIT
metadata.author
Microsoft
metadata.version
1.0.0
metadata.package
azure-ai-contentsafety

Azure AI Content Safety SDK for Python

Detect harmful user-generated and AI-generated content in applications.

Installation

bash
pip install azure-ai-contentsafety

Environment Variables

bash
CONTENT_SAFETY_ENDPOINT=https://<resource>.cognitiveservices.azure.com  # Required for all auth methods
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production
CONTENT_SAFETY_KEY=<your-api-key>  # Only required for the legacy API-key auth path below

Authentication & Lifecycle

🔑 Two rules apply to every code sample below:

  1. Prefer DefaultAzureCredential. It works locally (Azure CLI / VS Code / Developer CLI) and in Azure (managed identity, workload identity) with no code change. Avoid connection strings, account/API keys — they bypass Entra audit and rotation.
    • Local dev: DefaultAzureCredential works as-is.
    • Production: set AZURE_TOKEN_CREDENTIALS=prod (or AZURE_TOKEN_CREDENTIALS=<specific_credential>) to constrain the credential chain to production-safe credentials.
  2. Wrap every client in a context manager so HTTP transports, sockets, and token caches are released deterministically:
    • Sync: with <Client>(...) as client:
    • Async: async with <Client>(...) as client: and async with DefaultAzureCredential() as credential: (from azure.identity.aio)

Snippets may abbreviate this setup, but production code should always follow both rules.

python
import os
from azure.identity import DefaultAzureCredential, ManagedIdentityCredential
from azure.ai.contentsafety import ContentSafetyClient
from azure.ai.contentsafety.models import AnalyzeTextOptions

# Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
credential = DefaultAzureCredential(require_envvar=True)
# Or use a specific credential directly in production:
# See https://learn.microsoft.com/python/api/overview/azure/identity-readme?view=azure-python#credential-classes
# credential = ManagedIdentityCredential()

with ContentSafetyClient(
    endpoint=os.environ["CONTENT_SAFETY_ENDPOINT"],
    credential=credential,
) as client:
    response = client.analyze_text(AnalyzeTextOptions(text="Hello, world!"))
Legacy: API Key (existing keyed deployments)

New code should use DefaultAzureCredential above. Use AzureKeyCredential only if you have an existing keyed deployment that hasn't been migrated to Entra ID yet — for example, regulated environments still completing their Entra rollout.

python
import os
from azure.core.credentials import AzureKeyCredential
from azure.ai.contentsafety import ContentSafetyClient
from azure.ai.contentsafety.models import AnalyzeTextOptions

with ContentSafetyClient(
    endpoint=os.environ["CONTENT_SAFETY_ENDPOINT"],
    credential=AzureKeyCredential(os.environ["CONTENT_SAFETY_KEY"]),
) as client:
    response = client.analyze_text(AnalyzeTextOptions(text="Hello, world!"))

The BlocklistClient accepts the same AzureKeyCredential if you also need to manage blocklists with a key.

Analyze Text

python
from azure.ai.contentsafety import ContentSafetyClient
from azure.ai.contentsafety.models import AnalyzeTextOptions, TextCategory
from azure.identity import DefaultAzureCredential

with ContentSafetyClient(endpoint, DefaultAzureCredential()) as client:
    request = AnalyzeTextOptions(text="Your text content to analyze")
    response = client.analyze_text(request)

    # Check each category
    for category in [TextCategory.HATE, TextCategory.SELF_HARM, 
                     TextCategory.SEXUAL, TextCategory.VIOLENCE]:
        result = next((r for r in response.categories_analysis 
                       if r.category == category), None)
        if result:
            print(f"{category}: severity {result.severity}")

Analyze Image

python
from azure.ai.contentsafety import ContentSafetyClient
from azure.ai.contentsafety.models import AnalyzeImageOptions, ImageData
from azure.identity import DefaultAzureCredential
import base64

with ContentSafetyClient(endpoint, DefaultAzureCredential()) as client:
    # From file
    with open("image.jpg", "rb") as f:
        image_data = base64.b64encode(f.read()).decode("utf-8")

    request = AnalyzeImageOptions(
        image=ImageData(content=image_data)
    )

    response = client.analyze_image(request)

    for result in response.categories_analysis:
        print(f"{result.category}: severity {result.severity}")
Image from URL
python
from azure.ai.contentsafety.models import AnalyzeImageOptions, ImageData

request = AnalyzeImageOptions(
    image=ImageData(blob_url="https://example.com/image.jpg")
)

response = client.analyze_image(request)

Text Blocklist Management

Create Blocklist
python
from azure.ai.contentsafety import BlocklistClient
from azure.ai.contentsafety.models import TextBlocklist
from azure.identity import DefaultAzureCredential

with BlocklistClient(endpoint, DefaultAzureCredential()) as blocklist_client:
    blocklist = TextBlocklist(
        blocklist_name="my-blocklist",
        description="Custom terms to block"
    )

    result = blocklist_client.create_or_update_text_blocklist(
        blocklist_name="my-blocklist",
        options=blocklist
    )
Add Block Items
python
from azure.ai.contentsafety.models import AddOrUpdateTextBlocklistItemsOptions, TextBlocklistItem

items = AddOrUpdateTextBlocklistItemsOptions(
    blocklist_items=[
        TextBlocklistItem(text="blocked-term-1"),
        TextBlocklistItem(text="blocked-term-2")
    ]
)

result = blocklist_client.add_or_update_blocklist_items(
    blocklist_name="my-blocklist",
    options=items
)
Analyze with Blocklist
python
from azure.ai.contentsafety.models import AnalyzeTextOptions

request = AnalyzeTextOptions(
    text="Text containing blocked-term-1",
    blocklist_names=["my-blocklist"],
    halt_on_blocklist_hit=True
)

response = client.analyze_text(request)

if response.blocklists_match:
    for match in response.blocklists_match:
        print(f"Blocked: {match.blocklist_item_text}")

Severity Levels

Text analysis returns 4 severity levels (0, 2, 4, 6) by default. For 8 levels (0-7):

python
from azure.ai.contentsafety.models import AnalyzeTextOptions, AnalyzeTextOutputType

request = AnalyzeTextOptions(
    text="Your text",
    output_type=AnalyzeTextOutputType.EIGHT_SEVERITY_LEVELS
)

Harm Categories

CategoryDescription
HateAttacks based on identity (race, religion, gender, etc.)
SexualSexual content, relationships, anatomy
ViolencePhysical harm, weapons, injury
SelfHarmSelf-injury, suicide, eating disorders
Show full SKILL.md (190 more words)Show less

Severity Scale

LevelText RangeImage RangeMeaning
0SafeSafeNo harmful content
2LowLowMild references
4MediumMediumModerate content
6HighHighSevere content

Client Types

ClientPurpose
ContentSafetyClientAnalyze text and images
BlocklistClientManage custom blocklists

Best Practices

  1. Pick sync OR async and stay consistent. Do not mix azure.ai.contentsafety sync clients with azure.ai.contentsafety.aio async clients in the same call path. Choose one mode per module.
  2. Always use context managers for clients and async credentials. Wrap every client in with ContentSafetyClient(...) as client: (sync) or async with ContentSafetyClient(...) as client: (async). For async DefaultAzureCredential from azure.identity.aio, also use async with credential: so tokens and transports are cleaned up.
  3. Use blocklists for domain-specific terms
  4. Set severity thresholds appropriate for your use case
  5. Handle multiple categories — content can be harmful in multiple ways
  6. Use halt_on_blocklist_hit for immediate rejection
  7. Log analysis results for audit and improvement
  8. Consider 8-severity mode for finer-grained control
  9. Pre-moderate AI outputs before showing to users

Reference Files

FileContents
references/capabilities.mdAdditional non-hero capabilities, operation-group coverage, and production checklists.
references/non-hero-scenarios.mdDedicated non-hero examples for secondary/advanced scenarios.

© microsoft, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 2 other files (references) in .github/plugins/azure-sdk-python/skills/azure-ai-contentsafety-py of microsoft/skills.

  • SKILL.md
  • references/capabilities.md
  • references/non-hero-scenarios.md

Open the folder on GitHubat commit d5741a1

Used in 5 other repositories

We found 14 copies of this SKILL.md (exact, near-identical or edited) in other folders, from 5 other GitHub owners. This page covers the copy in microsoft/skills, which our catalogue first saw on October 7, 2026.

Compare with similar skills

Azure AI Contentsafety Py next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Azure AI Contentsafety Py compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Azure AI Contentsafety Py this skillmicrosoft/skills3.1k5 repos~2.2kAutomated safety check: PassMIT
Azure Architecture Autopilotgithub/awesome-copilot40k1 repos~1.9kAutomated safety check: PassMIT
Terraform Azurerm Set Diff Analyzergithub/awesome-copilot40k1 repos~547Automated safety check: PassMIT
Osmo Lerobot Trainingmicrosoft/physical-ai-toolchain126—~3.8kAutomated safety check: NotesMIT
Azure AI Deploytimothywarner-org/claude-code224—~731Automated safety check: NotesMIT
Apex Azure Bicep Patternsjonathan-vella/apex217—~2.5kAutomated safety check: PassMIT

Similar skills

  • Azure Architecture Autopilot

    github/awesome-copilot

    Official

    Designs Azure infrastructure from a natural-language description, or diagrams an existing resource group, then refines the design through conversation and deploys it with Bicep.

    40k GitHub starsUsed in 1 repo~1.9k tokens
    DevOps & CloudAuto-check passed
  • Official

    Analyze Terraform plan JSON output for AzureRM Provider to distinguish between false-positive diffs (order-only changes in Set-type attributes) and actual resource changes.

    40k GitHub starsUsed in 1 repo~547 tokens
    DevOps & CloudAuto-check passed
  • Osmo Lerobot Training

    microsoft/physical-ai-toolchain

    Official

    Submit, monitor, analyze, and evaluate LeRobot imitation learning training jobs on OSMO with Azure ML MLflow integration and inference evaluation - Brought to you by microsoft/physical-ai-toolchain

    126 GitHub stars~3.8k tokensUpdated yesterday
    DevOps & CloudAuto-check: notes
  • Azure AI Deploy

    timothywarner-org/claude-code

    Ship a Python generative-AI app to Azure the keyless way, using DefaultAzureCredential and azd.

    224 GitHub stars~731 tokensUpdated 2 mo ago
    DevOps & CloudAuto-check: notes
  • Apex Azure Bicep Patterns

    jonathan-vella/apex

    UTILITY SKILL — Reusable Azure Bicep patterns: hub-spoke, private endpoints, diagnostics, AVM composition.

    217 GitHub stars~2.5k tokensUpdated today
    DevOps & CloudAuto-check passed
  • Python Azure Iot Edge Modules

    github/awesome-copilot

    Official

    Build and operate Python Azure IoT Edge modules with robust messaging, deployment manifests, observability, and production readiness checks.

    40k GitHub starsUsed in 1 repo~1.1k tokens
    DevOps & CloudAuto-check passed

More from microsoft/skills

All 150 skills in this repo
  • Official

    Covers producer, consumer, and checkpoint-store setup for Azure Event Hubs streaming in Python, with Entra ID auth and partition targeting.

    3.1k GitHub starsUsed in 1 repo~2.3k tokens
    Auto-check passed
  • Official

    Builds podcast-style audio narration from text with Azure OpenAI's GPT Realtime Mini over WebSocket, from a Python FastAPI backend to a React player.

    3.1k GitHub starsUsed in 1 repo~947 tokens
    Auto-check passed
  • Frontend UI Dark TS

    microsoft/skills

    Official

    Build dark-themed React applications using Tailwind CSS with custom theming, glassmorphism effects, and Framer Motion animations.

    3.1k GitHub starsUsed in 5 repos~3.6k tokens
    Auto-check passed
  • Pydantic Models Py

    microsoft/skills

    Official

    Create Pydantic models following the multi-model pattern with Base, Create, Update, Response, and InDB variants.

    3.1k GitHub starsUsed in 5 repos~496 tokens
    Auto-check passed
  • Official

    Reference for building on Microsoft Foundry with the azure-ai-projects Python SDK: project clients, versioned agents, evaluations, connections, datasets and indexes.

    3.1k GitHub stars~2.8k tokensUpdated yesterday
    Auto-check passed
  • Skill Creator

    microsoft/skills

    Official

    Guide for creating effective skills for AI coding agents working with Azure SDKs and Microsoft Foundry services.

    3.1k GitHub starsUsed in 5 repos~17k tokens
    Auto-check passed

Questions about Azure AI Contentsafety Py

What does Azure AI Contentsafety Py do?

Azure AI Content Safety SDK for Python. An agent skill from microsoft/skills. Azure AI Contentsafety Py is an agent skill from microsoft/skills, published by the product's own GitHub organization. Azure AI Content Safety SDK for Python.

When should I use Azure AI Contentsafety Py?

Azure AI Contentsafety Py fits situations like: detecting harmful content in text and images with multi-severity classification; tasks that involve LLM guardrails.

How do I install Azure AI Contentsafety Py in Claude Code?

Run `npx skills add microsoft/skills --skill azure-ai-contentsafety-py -a claude-code`. Or copy the skill folder (.github/plugins/azure-sdk-python/skills/azure-ai-contentsafety-py in microsoft/skills) into .claude/skills/azure-ai-contentsafety-py in your project. Claude Code loads it when a task matches its description.

How do I install Azure AI Contentsafety Py in Codex?

Run `npx skills add microsoft/skills --skill azure-ai-contentsafety-py -a codex`. Or copy the skill folder (.github/plugins/azure-sdk-python/skills/azure-ai-contentsafety-py in microsoft/skills) into .agents/skills/azure-ai-contentsafety-py in your project. Codex loads it when a task matches its description.

Can I use Azure AI Contentsafety Py in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add microsoft/skills --skill azure-ai-contentsafety-py -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/azure-ai-contentsafety-py, .gemini/skills/azure-ai-contentsafety-py, .github/skills/azure-ai-contentsafety-py and .opencode/skills/azure-ai-contentsafety-py in your project.

What does Azure AI Contentsafety Py need to run?

Going by SKILL.md and its folder, Azure AI Contentsafety Py needs the command-line tools its instructions call (pip) and credentials named AZURE_TOKEN_CREDENTIALS and CONTENT_SAFETY_KEY. Our summary lists: Python 3; A credential in CONTENT_SAFETY_KEY.

Does Azure AI Contentsafety Py access the network?

SKILL.md names 1 domain. In commands or code: learn.microsoft.com; the agent is likely to contact it when it follows the instructions. This is read from the text; nothing was executed.

Is Azure AI Contentsafety Py safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Azure AI Contentsafety Py use?

Azure AI Contentsafety Py is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Azure AI Contentsafety Py use?

About 2.2k tokens (SKILL.md is roughly 9k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 586 tokens, read only when the agent opens those files.

What are the alternatives to Azure AI Contentsafety Py?

Skills that share tags, products or a category with Azure AI Contentsafety Py: Azure Architecture Autopilot (github/awesome-copilot, 40k stars), Terraform Azurerm Set Diff Analyzer (github/awesome-copilot, 40k stars), Osmo Lerobot Training (microsoft/physical-ai-toolchain, 126 stars) and Azure AI Deploy (timothywarner-org/claude-code, 224 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Azure AI Contentsafety Py?

microsoft (a GitHub organization, an official publisher) maintains it in microsoft/skills, which has 3,097 GitHub stars. The repository holds 150 skills in this directory. The repository was last updated on October 9, 2026.

Source: microsoft/skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.