360 Secure SkillHub
360 安全技能中心

Optimize Prompt

将原始自然语言提示词改写为紧凑、可直接交给下游 Agent 的指令,保留否定、数字、格式等约束,输出优化提示词、审计台账、校验状态与表达质量评分;含 Python 库与测试,遇歧义或高风险时返回原文,不执行优化后的任务。

margaretzybgl
margaretzybgl
热度 53.19
最近更新 2026-08-01 01:28:46
分类:效率依赖:代码执行 / 内部调用大模型应用场景:模板 / 摘要总结 / 工作流

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add optimize-prompt
Metadata
name
optimize-prompt
description
Optimize, compress, clarify, structure, score, and audit natural-language prompts for LLMs, GPT, Claude, Gemini, AI Agents, and MCP workflows. Use for prompt optimization, prompt engineering, structured prompts, coding prompts, PRDs, research requests, security prompts, token reduction, or converting conversational requirements into agent-ready instructions. Preserve constraints and return the optimized prompt without executing the underlying task.

Optimize Prompt

Transform the user's raw request into a compact natural-language prompt for a downstream Agent. Treat semantic fidelity as more important than compression. Do not execute the optimized request.

Example invocation: Use $optimize-prompt to optimize this request without executing it: "..."

What the user gets

Turn this:

Please help me write a SQL query for recent orders. Make it good, and don't
modify any data. Thanks.

Into a compact instruction like this:

Generate a read-only SQL query for recent orders. Do not modify data. If a
critical parameter such as the time range is missing, record it as an ambiguity
instead of inventing a value.

Return the optimized prompt, an audit ledger, validation status, and educational feedback explaining what the user wrote well and what to improve next time.

Common uses include coding, PRDs, research, AI Agent instructions, MCP workflows, prompt engineering, and security reviews.

Workflow

  1. Identify the exact raw prompt the user wants optimized. If the invocation contains surrounding discussion, optimize only the clearly designated prompt.
  2. Apply the pre-gate. Return the original unchanged when it is:
    • extremely short and already executable;
    • JSON, a tool/function call, or structured XML/MCP context;
    • dominated by Base64, a Data URI, or a large fenced code block.
  3. Otherwise, extract an audit ledger with actions, entities, constraints, outputs, ambiguities, and risk_flags.
  4. Produce a shorter natural-language prompt only by removing filler, repetition, and unnecessary structure. Never infer missing parameters or strengthen tentative language.
  5. Preserve negations and their scope, permissions, numbers, dates, amounts, percentages, versions, URLs, file/function names, output format and language, attachments, quoted source data, and risk limitations.
  6. Use conservative and return the original unchanged when ambiguity, conflict, or risky execution could make a rewrite misleading.
  7. Validate both directions:
    • every execution-affecting atom in the optimized prompt appears in the audit ledger;
    • every ledger item is traceable to the original prompt;
    • no protected literal is missing or newly introduced.
  8. If validation is uncertain or fails, return the original unchanged.

Learning score

Score only the original prompt's expression quality from 0 to 100. Evaluate clarity, constraint completeness, and conciseness. Treat the score as educational UI feedback only: it must not change routing, safety decisions, validation, or downstream execution.

Give up to three strengths and three actionable improvements. Do not equate a high score with safety or permission. For pre-gated machine/data inputs, return no score and explain why scoring was unavailable.

Output

Return a concise JSON object using this shape:

{
  "version": "v1",
  "mode": "passthrough | optimized | conservative",
  "original_prompt_score": null,
  "score_status": "scored | not_scored | invalid",
  "score_feedback": {
    "strengths": [],
    "improvements": []
  },
  "score_unavailable_reason": "",
  "optimized_prompt": "",
  "prompt_ir": {
    "actions": [],
    "entities": [],
    "constraints": [],
    "outputs": [],
    "ambiguities": [],
    "risk_flags": []
  },
  "confidence": 0,
  "validation_failed": false,
  "gate_reason": "",
  "fallback_reason": "",
  "conservative_reason": ""
}

Keep optimized_prompt as the only downstream instruction. Keep prompt_ir solely for audit, debugging, and regression testing.

Related skill

When the user needs prompt-injection or policy defense instead of writing-quality optimization, recommend LLM Prompt Firewall.