Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计通过

ai-checking-outputsAI 检查输出

Agent Skill

ai-checking-outputs 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

306

周安装

13

GitHub Stars

3

下载量

107
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:ai-checking-outputs(AI 检查输出)
来源仓库:https://github.com/lebsral/dspy-programming-not-prompting-lms-skills
仓库路径:skills/ai-checking-outputs
安装命令:
npx skills add https://github.com/lebsral/dspy-programming-not-prompting-lms-skills --skill ai-checking-outputs
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/lebsral/dspy-programming-not-prompting-lms-skills --skill ai-checking-outputs

简介

用于查找、检索和筛选相关信息。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中根据关键词、任务场景或来源线索快速定位候选结果。
  • 可结合来源仓库、安装命令和原始 README 继续核验具体用法。
  • 安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。
  • ai-checking-outputs 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Check AI Output Before It Ships

Guide the user through adding verification and guardrails so bad AI outputs never reach users. The pattern: generate, check, fix or reject.

Step 1: Understand what to check

Ask the user:

  1. What could go wrong? (hallucinations, wrong format, offensive content, missing info, factual errors?)
  2. How strict does it need to be? (reject bad outputs vs. try to fix them?)
  3. What's the cost of a bad output reaching users? (annoyance vs. legal/safety risk)

Step 2: Quick wins — DSPy assertions

The simplest way to add checks. dspy.Assert is a hard stop (retry if violated), dspy.Suggest is a soft nudge:

import dspy

class CheckedResponder(dspy.Module):
    def __init__(self):
        self.respond = dspy.ChainOfThought(GenerateResponse)

    def forward(self, question):
        result = self.respond(question=question)

        # Hard checks — will retry if these fail
        dspy.Assert(
            len(result.answer) > 0,
            "Must produce an answer"
        )
        dspy.Assert(
            len(result.answer.split()) <= 200,
            "Answer must be under 200 words"
        )

        # Soft checks — hints for improvement
        dspy.Suggest(
            "I don't know" not in result.answer.lower(),
            "Try to provide a substantive answer"
        )
        dspy.Suggest(
            not any(word in result.answer.lower() for word in ["definitely", "absolutely", "100%"]),
            "Avoid overconfident language"
        )

        return result

DSPy will automatically retry the LM call (with the assertion feedback) when an Assert fails, up to a configurable number of times.

Step 3: Format validation

Type-based validation (automatic)

DSPy validates typed outputs automatically:

from typing import Literal
from pydantic import BaseModel, Field

class Response(BaseModel):
    answer: str = Field(min_length=1, max_length=500)
    confidence: float = Field(ge=0.0, le=1.0)
    category: str

class MySignature(dspy.Signature):
    question: str = dspy.InputField()
    response: Response = dspy.OutputField()

Pydantic catches malformed JSON, out-of-range values, and wrong types before your code ever sees them.

Custom validation in the module

import re

class ValidatedExtractor(dspy.Module):
    def __init__(self):
        self.extract = dspy.ChainOfThought(ExtractContact)

    def forward(self, text):
        result = self.extract(text=text)

        # Validate email format
        dspy.Assert(
            re.match(r"[^@]+@[^@]+\.[^@]+", result.email or ""),
            "Email must be a valid email address"
        )

        # Validate phone format
        dspy.Assert(
            len(re.sub(r"\D", "", result.phone or "")) >= 10,
            "Phone must have at least 10 digits"
        )

        return result

Step 4: Factual verification

Self-check — ask the AI to verify its own output

class VerifyFacts(dspy.Signature):
    """Check if the answer is supported by the given context."""
    context: list[str] = dspy.InputField(desc="Source documents")
    answer: str = dspy.InputField(desc="Generated answer to verify")
    is_supported: bool = dspy.OutputField(desc="Is the answer fully supported by the context?")
    unsupported_claims: list[str] = dspy.OutputField(desc="Claims not found in context")

class GroundedResponder(dspy.Module):
    def __init__(self):
        self.retrieve = dspy.Retrieve(k=5)
        self.answer = dspy.ChainOfThought(AnswerFromDocs)
        self.verify = dspy.Predict(VerifyFacts)

    def forward(self, question):
        context = self.retrieve(question).passages
        response = self.answer(context=context, question=question)

        # Verify the answer is grounded in sources
        check = self.verify(context=context, answer=response.answer)
        dspy.Assert(
            check.is_supported,
            f"Answer contains unsupported claims: {check.unsupported_claims}. "
            "Rewrite using only information from the context."
        )

        return response

Cross-check — generate two ways, compare

class CrossCheckedAnswer(dspy.Module):
    def __init__(self):
        self.answer_a = dspy.ChainOfThought(AnswerQuestion)
        self.answer_b = dspy.ChainOfThought(AnswerQuestion)
        self.compare = dspy.ChainOfThought(CompareAnswers)

    def forward(self, question):
        a = self.answer_a(question=question)
        b = self.answer_b(question=question)

        comparison = self.compare(
            question=question,
            answer_a=a.answer,
            answer_b=b.answer,
        )

        dspy.Assert(
            comparison.agree,
            "Two independent generations disagree — the answer may be unreliable"
        )

        return a

class CompareAnswers(dspy.Signature):
    """Check if two independently generated answers agree."""
    question: str = dspy.InputField()
    answer_a: str = dspy.InputField()
    answer_b: str = dspy.InputField()
    agree: bool = dspy.OutputField(desc="Do the answers substantially agree?")
    discrepancy: str = dspy.OutputField(desc="What they disagree on, if anything")

Step 5: Safety and content filtering

Block harmful outputs

BLOCKED_PATTERNS = [
    r"\b(password|secret|api.?key)\b",
    r"\b\d{3}-\d{2}-\d{4}\b",  # SSN pattern
]

class SafeResponder(dspy.Module):
    def __init__(self):
        self.respond = dspy.ChainOfThought(GenerateResponse)

    def forward(self, question):
        result = self.respond(question=question)

        # Check for leaked sensitive data
        for pattern in BLOCKED_PATTERNS:
            dspy.Assert(
                not re.search(pattern, result.answer, re.IGNORECASE),
                f"Response may contain sensitive data (pattern: {pattern})"
            )

        return result

AI-as-safety-judge

class SafetyCheck(dspy.Signature):
    """Check if the response is safe and appropriate."""
    question: str = dspy.InputField()
    response: str = dspy.InputField()
    is_safe: bool = dspy.OutputField()
    concern: str = dspy.OutputField(desc="Safety concern if not safe, empty if safe")

class SafetyCheckedResponder(dspy.Module):
    def __init__(self):
        self.respond = dspy.ChainOfThought(GenerateResponse)
        self.check = dspy.Predict(SafetyCheck)

    def forward(self, question):
        result = self.respond(question=question)

        safety = self.check(question=question, response=result.answer)
        dspy.Assert(
            safety.is_safe,
            f"Response flagged as unsafe: {safety.concern}. Regenerate."
        )

        return result

Step 6: Generate → Filter → Pick best (ensemble pattern)

For high-stakes outputs, generate multiple candidates and filter:

class FilteredEnsemble(dspy.Module):
    def __init__(self, num_candidates=5):
        self.generators = [dspy.ChainOfThought(GenerateAnswer) for _ in range(num_candidates)]
        self.judge = dspy.ChainOfThought(RankAnswers)

    def forward(self, question):
        candidates = []
        for gen in self.generators:
            try:
                result = gen(question=question)
                # Only keep candidates that pass basic checks
                if len(result.answer) > 0 and len(result.answer.split()) < 200:
                    candidates.append(result.answer)
            except Exception:
                continue

        dspy.Assert(len(candidates) > 0, "No valid candidates generated")

        return self.judge(question=question, candidates=candidates)

class RankAnswers(dspy.Signature):
    """Pick the best answer from the candidates."""
    question: str = dspy.InputField()
    candidates: list[str] = dspy.InputField()
    best_answer: str = dspy.OutputField()

How backtracking works

When dspy.Assert fails, DSPy doesn't just retry blindly:

  1. The assertion failure is caught
  2. The error message is fed back to the LM as additional context
  3. The LM retries with this feedback (e.g., "your answer was 350 words, must be under 280")
  4. This repeats up to max_backtrack_attempts times (default: 2)
  5. If all retries fail, the assertion raises an error

This is why specific error messages matter — they're the model's self-correction instructions. "Response is 350 words, must be under 280" is much more useful than "too long."

When combined with optimization (/ai-improving-accuracy), the model learns to satisfy constraints on the first try, reducing retries in production.

Key patterns

  • Assert for hard requirements — format, length, safety. DSPy retries automatically.
  • Suggest for soft preferences — style, tone, detail level. Won't block but nudges.
  • Pydantic for structure — catches malformed output automatically.
  • Self-verification for facts — ask the AI "is this grounded in the sources?"
  • Cross-checking for reliability — generate twice independently, compare.
  • Regex for sensitive data — block SSNs, API keys, passwords in output.
  • Ensemble for high stakes — generate many, filter, pick the best.

Checklist: what to check

CheckWhen to useHow
Non-empty outputAlwaysdspy.Assert(len(answer) > 0,...)
Length limitsUser-facing textdspy.Assert(len(answer.split()) < N,...)
Valid formatStructured outputPydantic model + dspy.Assert
Grounded in sourcesRAG / doc searchVerification signature
No sensitive dataAny user-facing outputRegex patterns
Safe contentPublic-facing appsAI safety judge
ConsistentCritical decisionsCross-check with two generations
High qualityHigh-stakes outputsEnsemble + ranking

Gotchas

  • Claude writes vague assertion messages. dspy.Assert(check, "Bad output") gives the LM nothing to work with on retry. The error message is the model's self-correction instruction — make it specific: "Response is 350 words, must be under 280" not "too long".
  • Claude puts assertions outside the module. dspy.Assert and dspy.Suggest only trigger backtracking when called inside a dspy.Module.forward() method. Assertions in standalone scripts or outside forward() just raise exceptions with no retry.
  • Claude uses dspy.Assert for style preferences. Assert is a hard stop — if it fails after retries, the whole call errors. Use dspy.Suggest for soft preferences like tone, detail level, or avoiding filler words. Reserve Assert for things that must be true (valid format, no PII, non-empty output).
  • Claude wraps every LM call in try/except to catch assertion failures. DSPy's backtracking handles Assert failures internally — catching the exception yourself defeats the retry mechanism. Let assertions propagate; only catch at the top level if you need a fallback for the case where all retries are exhausted.
  • Claude forgets that self-verification has a cost. Adding a VerifyFacts check doubles your LM calls. For low-stakes outputs (summaries, suggestions), dspy.Assert with format checks is sufficient. Reserve AI-as-judge verification for high-stakes outputs where a wrong answer has real consequences.

Additional resources

  • Use /ai-stopping-hallucinations for citation enforcement, faithfulness verification, and grounding AI in facts
  • Use /ai-following-rules for defining and enforcing content policies, format rules, and business constraints
  • Use /ai-building-pipelines to wire checks into multi-step systems
  • Use /ai-making-consistent for output consistency (not correctness)
  • Use /ai-testing-safety to stress-test your guardrails with adversarial attacks
  • Need to evaluate human work against criteria? Use /ai-scoring
  • Next: /ai-improving-accuracy to measure and improve quality
  • Not sure which skill to use next? Try /ai-do to get routed to the right one

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

37.8%
按下载量换算40

Claude

28.5%
按下载量换算30

Cursor

18.68%
按下载量换算20

Gemini CLI

10.06%
按下载量换算11

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills