Azure AI Content Safety for Python
Guides Python applications in detecting harmful text and images and enforcing custom blocklists.
The skill explicitly prefers DefaultAzureCredential, constrains production credential chains, and places endpoints, tokens, and API keys in environment variables; it also labels API keys as a legacy path and supports image URLs, logging, and blocklist management. Points are deducted because it does not require user confirmation before external Azure calls, adequately disclose that text, images, and URLs are sent to a cloud service, or address sensitive-content handling, log redaction, least-privilege Azure roles, rollback, or image-URL access risks.
The documentation is mostly consistent about synchronous client lifecycle, authentication preference, and separating sync from async usage, and it advises validating current API method names. However, an example uses an undefined endpoint variable, and the skill lacks exception, timeout, retry, quota, and network-failure handling plus skill-specific reproducible tests. Under static calibration, reliability is capped at 10, so it receives 7.
Triggers, Python SDK scope, text/image moderation, blocklists, and severity classification scenarios are fairly clear for coding agents using Azure AI Content Safety. It does not define non-fit boundaries, input limits, output contracts, exclusion triggers, Chinese-language quality, regional availability, or mainland-China network reachability.
The YAML metadata supplies name, MIT license, author, version, and package name. The material is organized into installation, authentication, core scenarios, best practices, and reference files. Points are deducted for the absence of a changelog, explicit maintenance owner and update path, dependency version constraints, FAQ, troubleshooting guidance, and cleanup/delete examples; some reference content is duplicated.
Examples cover text and image analysis, blocklists, severity levels, and client selection, providing directly usable guidance for common introductory implementations. Production error handling, a complete async path, threshold decisions, privacy handling, and cleanup paths remain incomplete, and example correctness is not supported by skill-specific execution evidence. Under static calibration, effectiveness is capped at 7, so it receives 6.
The skill provides limited Microsoft Learn attribution, a named package, and auditable code snippets. The repository also shows generic CI, Vally evaluation, and test-harness material, but the supplied evidence does not establish coverage of this skill's key paths or provide skill-specific test results or independent corroboration. Under static calibration, verifiability is capped at 5, so it receives 4.
- Before sending user text, image content, or remote image URLs to Azure, document the data flow, region, retention policy, and authorization boundary, and avoid logging sensitive analysis results verbatim.
- The examples leave endpoint undefined and omit exception, retry, timeout, quota, and complete async paths; validate method names, model fields, and severity semantics against version-pinned official documentation and project tests before adoption.
- Mainland-China network reachability, Azure regional availability, and enterprise proxy requirements are not addressed, so target-environment availability is unverified.
What it does & when to use it
This skill provides coding guidance for the Azure AI Content Safety SDK for Python. It covers text and image analysis, severity levels, four harm categories, and custom text blocklist management. It recommends DefaultAzureCredential with Microsoft Entra ID and deterministic client lifecycle management through context managers. It is a good fit for Python teams integrating Azure content moderation, provided they have an Azure Content Safety resource and authentication configured.
Guides an agent to install azure-ai-contentsafety, read CONTENT_SAFETY_ENDPOINT and related environment variables, create ContentSafetyClient or BlocklistClient instances, and call operations such as analyze_text, analyze_image, create_or_update_text_blocklist, and add_or_update_blocklist_items. It shows how to encode a local image or submit an image URL, inspect Hate, Sexual, Violence, and SelfHarm results with severities, select four- or eight-level output, and apply blocklists during text analysis.
- A Python developer moderating user-generated text before it is published can check hate, sexual, violence, and self-harm categories.
- A team building image uploads can analyze local images or image URLs before displaying them to users.
- An application owner with domain-specific prohibited terms can create a blocklist and reject text when a match is found.
- An AI product team can pre-moderate model outputs and log analysis results for auditing and improvement.
Pros & cons
- Covers text analysis, image analysis, and custom blocklist management.
- Includes concrete examples for four harm categories, severity levels, and eight-level output.
- Provides clear guidance for DefaultAzureCredential and synchronous or asynchronous client cleanup.
- Includes local-image, image-URL, blocklist-match, and AI-output pre-moderation patterns.
- Requires an Azure Content Safety resource, endpoint, and authentication; it does not run independently of Azure.
- The supplied material does not document pricing, quotas, regional availability, or retry behavior.
- The README describes a test harness, but provides no skill-specific test result for this skill.
- The skill references capabilities.md and non-hero-scenarios.md, whose contents are not included.
How to install
Add the repository to a coding agent with npx skills add microsoft/skills, then select the skill in the wizard. For manual installation, clone https://github.com/microsoft/skills and copy .github/plugins/azure-sdk-python/skills/azure-ai-contentsafety-py into the agent skill directory, such as .github/skills/. Install the Python SDK with: pip install azure-ai-contentsafety.
How to use
Useful trigger phrases include “azure-ai-contentsafety”, “ContentSafetyClient”, “content moderation”, “harmful content”, “text analysis”, and “image analysis”. Ask the agent to generate or update Python code for text analysis, image analysis, blocklist management, or severity configuration. Before running the code, set CONTENT_SAFETY_ENDPOINT; when using DefaultAzureCredential in production, set AZURE_TOKEN_CREDENTIALS=prod, and set CONTENT_SAFETY_KEY only for the documented legacy key-based path.
Compared to similar skills
The source explicitly contrasts DefaultAzureCredential with the legacy AzureKeyCredential path: new code should prefer DefaultAzureCredential, while AzureKeyCredential is intended for existing keyed deployments that have not migrated to Entra ID.