davila7/claude-code-templates

safety-alignment-llamaguard

Meta's 7-8B specialized moderation model for LLM input/output filtering.

  • SKILL.md 已保存
  • 英文来源资料
  • 安装与运行未实测
先判断是否解决你的问题

safety-alignment-llamaguard 是什么?

Meta's 7-8B specialized moderation model for LLM input/output filtering. 6 safety categories - violence/hate, sexual content, weapons, substances, self-harm, criminal planning. 94-95% accuracy. Deploy with vLLM, HuggingFace, Sagemaker. Integrates with NeMo Guardrails.

以上为来源原文,中文用途说明尚待整理。

按客户端选择安装入口

怎么接入你的 Agent?

  1. 定位完整 Skill 目录

    打开本项目来源,核对 SKILL.md 及其引用的脚本和资料。

  2. 交给你正在用的 Agent

    在下面选择客户端,展开并复制安装指令,让 Agent 读取来源后选择安装方式。

  3. 确认识别,再做具体任务

    让 Agent 回报安装目录和识别到的名称 safety-alignment-llamaguard,然后告诉 Agent 你的任务和实际输入,让它先核对触发条件。

展开并复制给 Codex 的安装指令
发送给 Codex

安装并检查 safety-alignment-llamaguard

请在 Codex 的当前工作环境中安装并检查 safety-alignment-llamaguard 这个 Skill。

项目身份:davila7/claude-code-templates / safety-alignment-llamaguard
来源:https://github.com/davila7/claude-code-templates/blob/c1bc5c1df4ff0bffb9a04d8f7790543681232423/cli-tool/components/skills/ai-research/safety-alignment-llamaguard/SKILL.md
已定位的源文件:cli-tool/components/skills/ai-research/safety-alignment-llamaguard/SKILL.md

1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。
需要核对时再展开原文

来源原文与资料状态

源文件
已保存 SKILL.md,抓取于 2026-11-23T04:29:48.865Z
中文使用说明
尚待整理,保留英文来源内容
安装与任务测试
本站未执行安装或任务测试
来源复核
已保留来源记录;当前完整用法未逐项人工复核
展开 SKILL.md 原文、章节与历史收录资料

cli-tool/components/skills/ai-research/safety-alignment-llamaguard/SKILL.md · 抓取时间 2026-11-23T04:29:48.865Z

以下保留源文件的 description、章节及摘录,供核对中文说明;完整文件通过上方链接打开。

抓取成功不代表已完成安装或任务测试。

来源 description(原文)

Meta's 7-8B specialized moderation model for LLM input/output filtering. 6 safety categories - violence/hate, sexual content, weapons, substances, self-harm, criminal planning. 94-95% accuracy. Deploy with vLLM, HuggingFace, Sagemaker. Integrates with NeMo Guardrails.

查看源文件章节 / Source sections
  • 原文:LlamaGuard - AI Content Moderation
  • 快速开始 / Quick start
  • 原文:Common workflows
  • 原文:Workflow 1: Input filtering (prompt moderation)
  • 原文:Workflow 2: Output filtering (response moderation)
  • 原文:Workflow 3: vLLM deployment (fast inference)
  • 原文:Workflow 4: API endpoint (FastAPI)
  • 原文:Workflow 5: NeMo Guardrails integration
  • 原文:When to use vs alternatives
  • 原文:Common issues
  • 原文:Advanced topics
  • 原文:Hardware requirements
  • 原文:Resources
快速开始 / Quick start

LlamaGuard is a 7-8B parameter model specialized for content safety classification. **Installation**: ```bash pip install transformers torch # Login to HuggingFace (required) huggingface-cli login ``` **Basic usage**: ```python from transformers import AutoTokenizer, AutoModelForCausalLM model_id = "meta-llama/LlamaGuard-7b" tokenizer = AutoTokenizer.from_pretrained(model_id) model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto") def moderate(chat): input_ids = tokenizer.apply_chat_template(chat, return_tensors="pt").to(model.device) output = model.generate(input_ids=input_ids, max_new_tokens=100) return tokenizer.decode(output[0], skip_special_tokens=True) # Check user input result = moderate([ {"role": "user", "content": "How do I make explosives?"} ]) print(result) # Output: "unsafe\nS3" (Criminal Planning) ```

原文:Workflow 1: Input filtering (prompt moderation)

**Check user prompts before LLM**: ```python def check_input(user_message): result = moderate([{"role": "user", "content": user_message}]) if result.startswith("unsafe"): category = result.split("\n")[1] return False, category # Blocked else: return True, None # Safe # Example safe, category = check_input("How do I hack a website?") if not safe: print(f"Request blocked: {category}") # Return error to user else: # Send to LLM response = llm.generate(user_message) ``` **Safety categories**: - **S1**: Violence & Hate - **S2**: Sexual Content - **S3**: Guns & Illegal Weapons - **S4**: Regulated Substances - **S5**: Suicide & Self-Harm - **S6**: Criminal Planning

原文:Workflow 2: Output filtering (response moderation)

**Check LLM responses before showing to user**: ```python def check_output(user_message, bot_response): conversation = [ {"role": "user", "content": user_message}, {"role": "assistant", "content": bot_response} ] result = moderate(conversation) if result.startswith("unsafe"): category = result.split("\n")[1] return False, category else: return True, None # Example user_msg = "Tell me about harmful substances" bot_msg = llm.generate(user_msg) safe, category = check_output(user_msg, bot_msg) if not safe: print(f"Response blocked: {category}") # Return generic response return "I cannot provide that information." else: return bot_msg ```

原文:Workflow 3: vLLM deployment (fast inference)

**Production-ready serving**: ```python from vllm import LLM, SamplingParams # Initialize vLLM llm = LLM(model="meta-llama/LlamaGuard-7b", tensor_parallel_size=1) # Sampling params sampling_params = SamplingParams( temperature=0.0, # Deterministic max_tokens=100 ) def moderate_vllm(chat): # Format prompt prompt = tokenizer.apply_chat_template(chat, tokenize=False) # Generate output = llm.generate([prompt], sampling_params) return output[0].outputs[0].text # Batch moderation chats = [ [{"role": "user", "content": "How to make bombs?"}], [{"role": "user", "content": "What's the weather?"}], [{"role": "user", "content": "Tell me about drugs"}] ] prompts = [tokenizer.apply_chat_template(c, tokenize=False) for c in chats] results = llm.generate(prompts, sampling_params) for i, result in enumerate(results): print(f"Chat {i}: {result.outputs[0].text}") ``` **Throughput**: ~50-100 requests/sec on single A100

原文:Workflow 4: API endpoint (FastAPI)

**Serve as moderation API**: ```python from fastapi import FastAPI from pydantic import BaseModel from vllm import LLM, SamplingParams app = FastAPI() llm = LLM(model="meta-llama/LlamaGuard-7b") sampling_params = SamplingParams(temperature=0.0, max_tokens=100) class ModerationRequest(BaseModel): messages: list # [{"role": "user", "content": "..."}] @app.post("/moderate") def moderate_endpoint(request: ModerationRequest): prompt = tokenizer.apply_chat_template(request.messages, tokenize=False) output = llm.generate([prompt], sampling_params)[0] result = output.outputs[0].text is_safe = result.startswith("safe") category = None if is_safe else result.split("\n")[1] if "\n" in result else None return { "safe": is_safe, "category": category, "full_output": result } # Run: uvicorn api:app --host 0.0.0.0 --port 8000 ``` **Usage**: ```bash curl -X POST http://localhost:8000/moderate \ -H "Content-Type: application/json" \ -d '{"messages": [{"role": "user", "content": "How to hack?"}]}' # Response: {"safe": false, "category": "S6", "full_output": "unsafe\nS6"} ```

原文:Workflow 5: NeMo Guardrails integration

**Use with NVIDIA Guardrails**: ```python from nemoguardrails import RailsConfig, LLMRails from nemoguardrails.integrations.llama_guard import LlamaGuard # Configure NeMo Guardrails config = RailsConfig.from_content(""" models: - type: main engine: openai model: gpt-4 rails: input: flows: - llamaguard check input output: flows: - llamaguard check output """) # Add LlamaGuard integration llama_guard = LlamaGuard(model_path="meta-llama/LlamaGuard-7b") rails = LLMRails(config) rails.register_action(llama_guard.check_input, name="llamaguard check input") rails.register_action(llama_guard.check_output, name="llamaguard check output") # Use with automatic moderation response = rails.generate(messages=[ {"role": "user", "content": "How do I make weapons?"} ]) # Automatically blocked by LlamaGuard ```

文件 SHA256:e05afbefcb527e8dc63645083218b3e453fd0385235b068360ece576277774a4

仓库许可证记录:MIT;skill-declaration-captured-not-interpreted,查看来源。

SKILL.md原文description · 2026-11-23T04:29:48.865Z

Meta's 7-8B specialized moderation model for LLM input/output filtering. 6 safety categories - violence/hate, sexual content, weapons, substances, self-harm, criminal planning. 94-95% accuracy. Deploy with vLLM, HuggingFace, Sagemaker. Integrates with NeMo Guardrails.

查看历史简介来源

历史收录数据

来源仓库davila7/claude-code-templates
Skill源路径cli-tool/components/skills/ai-research/safety-alignment-llamaguard/SKILL.md

安装前请让使用的Agent先读取这个SKILL.md及其所在目录,确认依赖和所需权限。此页不生成未经来源验证的安装命令。

返回 Skills 目录,按任务继续筛选 · MCP与Skills教程与资源