[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-f17b467e-8c81-4763-8b47-b63418945b80":3,"$flUfjOy3_n3Ag4UWI-WSTT147nPn56mlP9htKcPMX9XE":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"f17b467e-8c81-4763-8b47-b63418945b80","azure-ai-contentsafety-py","Azure AI内容安全SDK for Python。用于检测文本和图像中的有害内容，具有多严重程度分类。","cat_coding_devops","mod_coding","sickn33,coding","---\nname: azure-ai-contentsafety-py\ndescription: Azure AI Content Safety SDK for Python. Use for detecting harmful content in text and images with multi-severity classification.\nrisk: unknown\nsource: community\ndate_added: '2026-02-27'\n---\n\n# Azure AI Content Safety SDK for Python\n\nDetect harmful user-generated and AI-generated content in applications.\n\n## Installation\n\n```bash\npip install azure-ai-contentsafety\n```\n\n## Environment Variables\n\n```bash\nCONTENT_SAFETY_ENDPOINT=https:\u002F\u002F\u003Cresource>.cognitiveservices.azure.com\nCONTENT_SAFETY_KEY=\u003Cyour-api-key>\n```\n\n## Authentication\n\n### API Key\n\n```python\nfrom azure.ai.contentsafety import ContentSafetyClient\nfrom azure.core.credentials import AzureKeyCredential\nimport os\n\nclient = ContentSafetyClient(\n    endpoint=os.environ[\"CONTENT_SAFETY_ENDPOINT\"],\n    credential=AzureKeyCredential(os.environ[\"CONTENT_SAFETY_KEY\"])\n)\n```\n\n### Entra ID\n\n```python\nfrom azure.ai.contentsafety import ContentSafetyClient\nfrom azure.identity import DefaultAzureCredential\n\nclient = ContentSafetyClient(\n    endpoint=os.environ[\"CONTENT_SAFETY_ENDPOINT\"],\n    credential=DefaultAzureCredential()\n)\n```\n\n## Analyze Text\n\n```python\nfrom azure.ai.contentsafety import ContentSafetyClient\nfrom azure.ai.contentsafety.models import AnalyzeTextOptions, TextCategory\nfrom azure.core.credentials import AzureKeyCredential\n\nclient = ContentSafetyClient(endpoint, AzureKeyCredential(key))\n\nrequest = AnalyzeTextOptions(text=\"Your text content to analyze\")\nresponse = client.analyze_text(request)\n\n# Check each category\nfor category in [TextCategory.HATE, TextCategory.SELF_HARM, \n                 TextCategory.SEXUAL, TextCategory.VIOLENCE]:\n    result = next((r for r in response.categories_analysis \n                   if r.category == category), None)\n    if result:\n        print(f\"{category}: severity {result.severity}\")\n```\n\n## Analyze Image\n\n```python\nfrom azure.ai.contentsafety import ContentSafetyClient\nfrom azure.ai.contentsafety.models import AnalyzeImageOptions, ImageData\nfrom azure.core.credentials import AzureKeyCredential\nimport base64\n\nclient = ContentSafetyClient(endpoint, AzureKeyCredential(key))\n\n# From file\nwith open(\"image.jpg\", \"rb\") as f:\n    image_data = base64.b64encode(f.read()).decode(\"utf-8\")\n\nrequest = AnalyzeImageOptions(\n    image=ImageData(content=image_data)\n)\n\nresponse = client.analyze_image(request)\n\nfor result in response.categories_analysis:\n    print(f\"{result.category}: severity {result.severity}\")\n```\n\n### Image from URL\n\n```python\nfrom azure.ai.contentsafety.models import AnalyzeImageOptions, ImageData\n\nrequest = AnalyzeImageOptions(\n    image=ImageData(blob_url=\"https:\u002F\u002Fexample.com\u002Fimage.jpg\")\n)\n\nresponse = client.analyze_image(request)\n```\n\n## Text Blocklist Management\n\n### Create Blocklist\n\n```python\nfrom azure.ai.contentsafety import BlocklistClient\nfrom azure.ai.contentsafety.models import TextBlocklist\nfrom azure.core.credentials import AzureKeyCredential\n\nblocklist_client = BlocklistClient(endpoint, AzureKeyCredential(key))\n\nblocklist = TextBlocklist(\n    blocklist_name=\"my-blocklist\",\n    description=\"Custom terms to block\"\n)\n\nresult = blocklist_client.create_or_update_text_blocklist(\n    blocklist_name=\"my-blocklist\",\n    options=blocklist\n)\n```\n\n### Add Block Items\n\n```python\nfrom azure.ai.contentsafety.models import AddOrUpdateTextBlocklistItemsOptions, TextBlocklistItem\n\nitems = AddOrUpdateTextBlocklistItemsOptions(\n    blocklist_items=[\n        TextBlocklistItem(text=\"blocked-term-1\"),\n        TextBlocklistItem(text=\"blocked-term-2\")\n    ]\n)\n\nresult = blocklist_client.add_or_update_blocklist_items(\n    blocklist_name=\"my-blocklist\",\n    options=items\n)\n```\n\n### Analyze with Blocklist\n\n```python\nfrom azure.ai.contentsafety.models import AnalyzeTextOptions\n\nrequest = AnalyzeTextOptions(\n    text=\"Text containing blocked-term-1\",\n    blocklist_names=[\"my-blocklist\"],\n    halt_on_blocklist_hit=True\n)\n\nresponse = client.analyze_text(request)\n\nif response.blocklists_match:\n    for match in response.blocklists_match:\n        print(f\"Blocked: {match.blocklist_item_text}\")\n```\n\n## Severity Levels\n\nText analysis returns 4 severity levels (0, 2, 4, 6) by default. For 8 levels (0-7):\n\n```python\nfrom azure.ai.contentsafety.models import AnalyzeTextOptions, AnalyzeTextOutputType\n\nrequest = AnalyzeTextOptions(\n    text=\"Your text\",\n    output_type=AnalyzeTextOutputType.EIGHT_SEVERITY_LEVELS\n)\n```\n\n## Harm Categories\n\n| Category | Description |\n|----------|-------------|\n| `Hate` | Attacks based on identity (race, religion, gender, etc.) |\n| `Sexual` | Sexual content, relationships, anatomy |\n| `Violence` | Physical harm, weapons, injury |\n| `SelfHarm` | Self-injury, suicide, eating disorders |\n\n## Severity Scale\n\n| Level | Text Range | Image Range | Meaning |\n|-------|------------|-------------|---------|\n| 0 | Safe | Safe | No harmful content |\n| 2 | Low | Low | Mild references |\n| 4 | Medium | Medium | Moderate content |\n| 6 | High | High | Severe content |\n\n## Client Types\n\n| Client | Purpose |\n|--------|---------|\n| `ContentSafetyClient` | Analyze text and images |\n| `BlocklistClient` | Manage custom blocklists |\n\n## Best Practices\n\n1. **Use blocklists** for domain-specific terms\n2. **Set severity thresholds** appropriate for your use case\n3. **Handle multiple categories** — content can be harmful in multiple ways\n4. **Use halt_on_blocklist_hit** for immediate rejection\n5. **Log analysis results** for audit and improvement\n6. **Consider 8-severity mode** for finer-grained control\n7. **Pre-moderate AI outputs** before showing to users\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,67,1405,"2026-05-16 13:05:08",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"编程开发","coding","mdi-code-braces","代码生成、调试、审查，提升开发效率",2,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"DevOps","devops","mdi-cog-outline","CI\u002FCD、容器化、部署运维",3,162,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"80b35860-4057-441f-8e38-54b45840a3ac","1.0.0","azure-ai-contentsafety-py.zip",2157,"uploads\u002Fskills\u002Ff17b467e-8c81-4763-8b47-b63418945b80\u002Fazure-ai-contentsafety-py.zip","239d01e60d978c1fe102a0d87ec8e56b22d646106d4b804d3ba875b72c8004b2","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":6003}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]