azure-ai-contentsafety-ts – skill Viết lách & Nội dung cho agent AI
Phân tích văn bản và hình ảnh để phát hiện nội dung có hại, với danh sách chặn (blocklist) tùy chỉnh.
Cài skill azure-ai-contentsafety-ts bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-ai-contentsafety-ts-a1459.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /azure-ai-contentsafety-ts – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-ai-contentsafety-ts-a1459.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $azure-ai-contentsafety-ts – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-ai-contentsafety-ts-a1459.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /azure-ai-contentsafety-ts – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-ai-contentsafety-ts-a1459.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /azure-ai-contentsafety-ts – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Azure AI Content Safety REST SDK for TypeScript
Analyze text and images for harmful content with customizable blocklists.
Installation
npm install @azure-rest/ai-content-safety @azure/identity @azure/core-authEnvironment Variables
CONTENT_SAFETY_ENDPOINT=https://<resource>.cognitiveservices.azure.com
CONTENT_SAFETY_KEY=<api-key>Authentication
Important: This is a REST client. ContentSafetyClient is a function, not a class.
API Key
import ContentSafetyClient from "@azure-rest/ai-content-safety";
import { AzureKeyCredential } from "@azure/core-auth";
const client = ContentSafetyClient(
process.env.CONTENT_SAFETY_ENDPOINT!,
new AzureKeyCredential(process.env.CONTENT_SAFETY_KEY!)
);DefaultAzureCredential
import ContentSafetyClient from "@azure-rest/ai-content-safety";
import { DefaultAzureCredential } from "@azure/identity";
const client = ContentSafetyClient(
process.env.CONTENT_SAFETY_ENDPOINT!,
new DefaultAzureCredential()
);Analyze Text
import ContentSafetyClient, { isUnexpected } from "@azure-rest/ai-content-safety";
const result = await client.path("/text:analyze").post({
body: {
text: "Text content to analyze",
categories: ["Hate", "Sexual", "Violence", "SelfHarm"],
outputType: "FourSeverityLevels" // or "EightSeverityLevels"
}
});
if (isUnexpected(result)) {
throw result.body;
}
for (const analysis of result.body.categoriesAnalysis) {
console.log(`${analysis.category}: severity ${analysis.severity}`);
}Analyze Image
Base64 Content
import { readFileSync } from "node:fs";
const imageBuffer = readFileSync("./image.png");
const base64Image = imageBuffer.toString("base64");
const result = await client.path("/image:analyze").post({
body: {
image: { content: base64Image }
}
});
if (isUnexpected(result)) {
throw result.body;
}
for (const analysis of result.body.categoriesAnalysis) {
console.log(`${analysis.category}: severity ${analysis.severity}`);
}Blob URL
const result = await client.path("/image:analyze").post({
body: {
image: { blobUrl: "https://storage.blob.core.windows.net/container/image.png" }
}
});Blocklist Management
Create Blocklist
const result = await client
.path("/text/blocklists/{blocklistName}", "my-blocklist")
.patch({
contentType: "application/merge-patch+json",
body: {
description: "Custom blocklist for prohibited terms"
}
});
if (isUnexpected(result)) {
throw result.body;
}
console.log(`Created: ${result.body.blocklistName}`);Add Items to Blocklist
const result = await client
.path("/text/blocklists/{blocklistName}:addOrUpdateBlocklistItems", "my-blocklist")
.post({
body: {
blocklistItems: [
{ text: "prohibited-term-1", description: "First blocked term" },
{ text: "prohibited-term-2", description: "Second blocked term" }
]
}
});
if (isUnexpected(result)) {
throw result.body;
}
for (const item of result.body.blocklistItems ?? []) {
console.log(`Added: ${item.blocklistItemId}`);
}Analyze with Blocklist
const result = await client.path("/text:analyze").post({
body: {
text: "Text that might contain blocked terms",
blocklistNames: ["my-blocklist"],
haltOnBlocklistHit: false
}
});
if (isUnexpected(result)) {
throw result.body;
}
// Check blocklist matches
if (result.body.blocklistsMatch) {
for (const match of result.body.blocklistsMatch) {
console.log(`Blocked: "${match.blocklistItemText}" from ${match.blocklistName}`);
}
}List Blocklists
const result = await client.path("/text/blocklists").get();
if (isUnexpected(result)) {
throw result.body;
}
for (const blocklist of result.body.value ?? []) {
console.log(`${blocklist.blocklistName}: ${blocklist.description}`);
}Delete Blocklist
await client.path("/text/blocklists/{blocklistName}", "my-blocklist").delete();Harm Categories
| Category | API Term | Description |
|----------|----------|-------------|
| Hate and Fairness | Hate | Discriminatory language targeting identity groups |
| Sexual | Sexual | Sexual content, nudity, pornography |
| Violence | Violence | Physical harm, weapons, terrorism |
| Self-Harm | SelfHarm | Self-injury, suicide, eating disorders |
Severity Levels
| Level | Risk | Recommended Action |
|-------|------|-------------------|
| 0 | Safe | Allow |
| 2 | Low | Review or allow with warning |
| 4 | Medium | Block or require human review |
| 6 | High | Block immediately |
Output Types:
FourSeverityLevels(default): Returns 0, 2, 4, 6EightSeverityLevels: Returns 0-7
Content Moderation Helper
import ContentSafetyClient, {
isUnexpected,
TextCategoriesAnalysisOutput
} from "@azure-rest/ai-content-safety";
interface ModerationResult {
isAllowed: boolean;
flaggedCategories: string[];
maxSeverity: number;
blocklistMatches: string[];
}
async function moderateContent(
client: ReturnType<typeof ContentSafetyClient>,
text: string,
maxAllowedSeverity = 2,
blocklistNames: string[] = []
): Promise<ModerationResult> {
const result = await client.path("/text:analyze").post({
body: { text, blocklistNames, haltOnBlocklistHit: false }
});
if (isUnexpected(result)) {
throw result.body;
}
const analyses = result.body.categoriesAnalysis;
const expected = ["Hate", "SelfHarm", "Sexual", "Violence"];
if (!Array.isArray(analyses) || expected.some(category =>
!analyses.some(c => c.category === category && Number.isInteger(c.severity) && c.severity! >= 0 && c.severity! <= 7))) {
throw new Error("Incomplete moderation assessment");
}
const flaggedCategories = analyses
.filter(c => c.severity! > maxAllowedSeverity)
.map(c => c.category!);
const maxSeverity = Math.max(
...analyses.map(c => c.severity!)
);
const blocklistMatches = (result.body.blocklistsMatch ?? [])
.map(m => m.blocklistItemText!);
return {
isAllowed: flaggedCategories.length === 0 && blocklistMatches.length === 0,
flaggedCategories,
maxSeverity,
blocklistMatches
};
}API Endpoints
| Operation | Method | Path |
|-----------|--------|------|
| Analyze Text | POST | /text:analyze |
| Analyze Image | POST | /image:analyze |
| Create/Update Blocklist | PATCH | /text/blocklists/{blocklistName} |
| List Blocklists | GET | /text/blocklists |
| Delete Blocklist | DELETE | /text/blocklists/{blocklistName} |
| Add Blocklist Items | POST | /text/blocklists/{blocklistName}:addOrUpdateBlocklistItems |
| List Blocklist Items | GET | /text/blocklists/{blocklistName}/blocklistItems |
| Remove Blocklist Items | POST | /text/blocklists/{blocklistName}:removeBlocklistItems |
Key Types
import ContentSafetyClient, {
isUnexpected,
AnalyzeTextParameters,
AnalyzeImageParameters,
TextCategoriesAnalysisOutput,
ImageCategoriesAnalysisOutput,
TextBlocklist,
TextBlocklistItem
} from "@azure-rest/ai-content-safety";Best Practices
1. Always use isUnexpected() - Type guard for error handling
2. Set appropriate thresholds - Different categories may need different severity thresholds
3. Use blocklists for domain-specific terms - Supplement AI detection with custom rules
4. Log moderation decisions - Keep audit trail for compliance
5. Handle edge cases - Empty text, very long text, unsupported image formats
When to Use
This skill is applicable to execute the workflow or actions described in the overview.
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
A zero severity is a model result, not proof of safety; calibrate thresholds and escalation for the application. Missing analyses and service failures remain unassessed. Authorize cloud transmission of private content and do not expose raw error bodies or blocklisted text in public logs.
Skill liên quan
- azure-ai-contentunderstanding-py – SDK Azure AI Content Understanding cho Python. Dùng để trích xuất nội dung đa phương…
- azure-ai-translation-text-py – SDK Azure AI Text Translation để dịch văn bản thời gian thực, phiên âm…
- azure-ai-translation-ts – Dịch văn bản và tài liệu bằng client kiểu REST.
- content-creator – Skill chuyển hướng đã lỗi thời, định tuyến các yêu cầu 'content creator' cũ đến chuyên…
- content-humanizer – Làm cho nội dung do AI tạo ra nghe thật sự giống người — không chỉ được chỉnh sửa gọn…
- content-production – Quy trình sản xuất nội dung đầy đủ — đi từ trang trắng đến bài viết sẵn sàng xuất bản…
- content-strategy – Khi người dùng muốn lập chiến lược nội dung, quyết định nên tạo nội dung gì hoặc chọn…
- lora-qlora-recipes – Cấu hình tinh chỉnh có giám sát LoRA và QLoRA với các siêu tham số thực hành tốt nhất…