Eval Code 标志

Eval Code

组织
Calibre-Labs
eval-code

Write deterministic, code-based evaluator functions for an AI product. Use this skill whenever you need to write evaluators that check structural properties of AI outputs (format, count, presence, schema compliance) without calling another LLM. Also use when auditing existing code-based evaluators for brittleness, coverage gaps, or false positives.

概览

发布者Calibre-Labs
代码仓库reforge-ai-evals
技能名称eval-code
星标数
94
复刻数
9
附带文件
1
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载的 SKILL.md 文件,因此只有在请求确实匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 1 个随附文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 Calibre-Labs 发布于 GitHub。请在安装前查看源内容。

安装

在 TypingMind 中安装 Eval Code AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/Calibre-Labs/reforge-ai-evals/tree/main/skills/eval-code
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Calibre-Labs/reforge-ai-evals.git /tmp/reforge-ai-evals
mkdir -p .claude/skills
cp -r /tmp/reforge-ai-evals/skills/eval-code .claude/skills/eval-code
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Eval Code,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Eval Code。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Eval Code 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会获取指令,因此未使用的技能不会产生额外费用。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Code-Based Evaluator Skill

Code-based evaluators are deterministic functions that check AI outputs using regex, string operations, schema validation, or simple parsing — no LLM call required. They are fast, cheap, and produce the same result every time, which makes them the foundation of any eval suite.

The tradeoff: they can only check what is mechanically verifiable. They cannot assess whether the content is correct, relevant, or well-reasoned. Use them for structural properties; use LLM judges for semantic ones.

When to use this skill

Write code-based evaluators when the property you want to check can be expressed as:

  • Presence/absence: does the output contain X? (a section heading, a citation, a table)
  • Count: does the output contain exactly/at least N of something? (3 companies, 3 sources)
  • Format compliance: is the output in the expected structure? (JSON schema, markdown table)
  • Value range: is a number within expected bounds? (confidence score 0–1, year 1900–2030)
  • String match: does the output contain a required string? (company name, required disclaimer)

Do NOT write a code-based evaluator for:

  • Whether the companies ranked are the right companies (use an LLM judge)
  • Whether the rationale is coherent (use an LLM judge)
  • Whether citations are accurate (requires external lookup or LLM judge)

Workflow

Step 1 — Find the project's scorer contract

Before writing anything, look for where the project already keeps its evaluators: a scorers/ or evals/ folder, a types or contract file, existing scorers, a README that says how they run. If there is one, write in that language and follow it exactly: the function signature, the return shape, how the file is named, and where it goes. A new check should look like its neighbors.

For example, Mapper's course scorers live in scorers/course/, one TypeScript file per scorer. scorers/course/types.ts defines the contract: each file default-exports a function that takes a recorded session and returns { name, score: 0 | 1, metadata: { reason } }, and the file name is the scorer's id.

Use the Python signature and templates below only when the project has no contract of its own.

Step 2 — Identify the property to check

Start from the product's output requirements, not from what seems easy to check. Ask: "What must always be true in a valid output, regardless of the input?"

When the check comes from a rubric line and a trace code, read both. The rubric line defines what passes; the trace code names the failure you saw in traces. They can differ in scope. For example, Mapper's trace code 10 is "writes an essay instead of a map", but rubric line X1 also counts an analysis card as an output and limits the commentary around it to two sentences. When they differ, the rubric line wins. Put the rubric line and the trace code numbers in the scorer's header comment, so anyone reading results can trace a score back to what was found.

For each property, write one sentence: "A valid output must [verb] [object]."

Examples:

  • A valid output must contain exactly N ranked results.
  • A valid output must include at least 3 source citations.
  • A valid output must include a summary section before the detailed breakdown.
  • A valid output must be parseable as valid JSON matching the schema.

If the sentence requires words like "correctly" or "appropriate" or "relevant", stop — that property needs an LLM judge, not a code check.

Step 3 — Decide what happens when the check doesn't apply

Some rows have nothing to check: a request the agent should decline has no map to inspect, and a session with no table has no columns to count. Decide up front what those rows score, and put it in the reason. Usually that's a pass whose reason says why ("Row should be declined; no research answer to check"). If the project's contract supports skipping a row (a null score), use that instead. Never let a not-applicable row pass silently: the reason is how a reader tells "passed the check" from "had nothing to check".

Step 4 — Write the function signature

Use the project's contract from Step 1. Without one, this signature works across most eval platforms (Braintrust, LangSmith, custom runners):

python
def evaluator_name(output: str, input: str, expected: str = None) -> float | dict:
    ...

Return a float between 0.0 and 1.0, or a dict with at least a score key:

python
{"score": 0.5, "metadata": {"reason": "found 2 citations, expected 3"}}

Return metadata whenever partial credit is possible — it tells you why a score is 0.5, not just that it is.

Step 5 — Write the check, then find its failure modes

After writing the initial check, systematically ask:

  1. False positive: what valid output would this check incorrectly score 1.0? (e.g., a regex for "1." also matches "10." or "1.5B")
  2. False negative: what invalid output would this check incorrectly score 0.0? (e.g., a check for "Category:" misses "## Market Category" as a heading)
  3. Malicious input: could a model learn to game this check trivially? (e.g., always appending "Sources: [1] [2] [3]" with no real links)

Fix the top 1–2 failure modes. Don't over-engineer — accept that code-based checks have limits, and cover the rest with LLM judges.

Step 6 — Add partial credit where it makes sense

Binary (0/1) scoring is fine when the property is binary (either you have 3 companies or you don't). Add partial credit when:

  • There's a natural scale (0, 1, 2, 3 citations → 0.0, 0.33, 0.66, 1.0)
  • You want to distinguish "completely missing" from "partially present"

Don't add partial credit just because it feels nicer — it complicates threshold-setting. If the project's contract is binary (a score of 0 or 1, like Mapper's), stay binary and put the detail in the reason.

Step 7 — Test on known examples, then on recorded runs

Run the evaluator on at least:

  • 1 clearly valid output (should score 1.0)
  • 1 clearly invalid output (should score 0.0)
  • 1 edge case that you're not sure about

If the evaluator scores an obviously valid output below 0.8, the check is too strict. If it scores an obviously invalid output above 0.2, the check is too loose.

Then run it on the recorded runs you'll report, and read every failing row's reason against the output. A check you haven't read failures for is a check you don't know.

If it never fails on any run, say so when you report it. A check that passes everything isn't measuring a current problem; it's a regression guard that will catch the problem if a later change brings it back. That's useful, but it's a different claim from "this is fixed".


Output Format

Write each evaluator in the project's own format (Step 1): its language, its folder, one file per scorer if that's the convention. Without a project format, write a Python file with one function per evaluator. Either way, each function:

  • Has a clear docstring stating what it checks and what counts as pass/fail, plus the rubric line and trace code numbers it comes from
  • Returns a float or dict (not print statements)
  • Is independently testable (no global state, no side effects)
python
def result_count(output: str, input: str, expected: str = None) -> dict:
    """
    Checks that exactly N items appear in the output.

    Pass: output contains exactly N numbered/ranked entries
    Fail: output contains 0 to N-1 or N+ entries
    Partial (0.5): output contains N-1 entries (close but not compliant)

    Does NOT check whether the items are correct — use an LLM judge for content correctness.
    """
    ...

Common Patterns

Count with partial credit

python
import re

def result_count(output, input, expected=None):
    """
    Checks that exactly N ranked/numbered items appear in the output.
    Adapt the regex and expected count to your product's output format.
    """
    matches = re.findall(r'(?:^|\n)\s*\d+[\.\)]\s+\S', output, re.MULTILINE)
    expected_n = 3  # set to whatever your product should return
    if len(matches) == expected_n:
        return 1.0
    if len(matches) == expected_n - 1:
        return {"score": 0.5, "metadata": {"found": len(matches), "expected": expected_n}}
    return {"score": 0.0, "metadata": {"found": len(matches), "expected": expected_n}}

Presence check with multiple fallback patterns

python
def has_disclaimer(output, input, expected=None):
    """
    Checks that a required disclaimer or section header is present.
    Use multiple patterns to handle different formatting styles the model may produce.
    """
    patterns = [
        r'\*{0,2}disclaimer\*{0,2}\s*:',          # "**Disclaimer**:"
        r'^#{1,3}\s+.*disclaimer',                  # "## Disclaimer"
        r'(?:this is not|should not be construed)', # prose disclaimer
    ]
    for p in patterns:
        if re.search(p, output, re.IGNORECASE | re.MULTILINE):
            return 1.0
    return 0.0

JSON schema validation

python
import json
from jsonschema import validate, ValidationError

# Replace with the schema your product's output should conform to
SCHEMA = {
    "type": "object",
    "required": ["summary", "items", "sources"],
    "properties": {
        "items": {"type": "array", "minItems": 1},
        "sources": {"type": "array", "minItems": 1}
    }
}

def valid_schema(output, input, expected=None):
    try:
        data = json.loads(output)
        validate(data, SCHEMA)
        return 1.0
    except (json.JSONDecodeError, ValidationError) as e:
        return {"score": 0.0, "metadata": {"error": str(e)}}

Working Notes

  • Start with 2–3 evaluators, not 10. Four good code-based checks cover most structural requirements. More than 6 usually means you're checking things an LLM judge should handle.

  • Name evaluators after what they check, not what they penalize. has_sources is better than no_missing_citations. The positive framing makes pass/fail interpretation intuitive.

  • Don't hard-code company names or category strings. The check should be structural ("3 ranked items") not content-specific ("contains 'Salesforce'"). Content correctness is the judge's job.

  • Regex is fragile across output formats. If the model sometimes produces markdown tables, sometimes numbered lists, and sometimes prose — your regex needs to handle all three or you'll get false negatives. Test on diverse outputs before relying on a single pattern.

  • Score 0.5 sparingly. Partial credit is useful for training signal but confusing for dashboards. If you're not sure whether to give 0.5, default to binary and document the decision.

  • Track false positive rate manually. Run the evaluator on a sample of outputs and manually check the ones that score 1.0. If any are obviously invalid, your check is too loose.

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Eval Code AI 技能有什么作用?

Write deterministic, code-based evaluator functions for an AI product. Use this skill whenever you need to write evaluators that check structural properties of AI outputs (format, count, presence, schema compliance) without calling another LLM. Also use when auditing existing code-based evaluators for brittleness, coverage gaps, or false positives.

为什么在 TypingMind 中使用 Eval Code?

因为您只需安装一次,就能搭配任何模型使用。Eval Code 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型,甚至可以在聊天中途切换模型,而不会影响技能正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Eval Code?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/Calibre-Labs/reforge-ai-evals/tree/main/skills/eval-code。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Eval Code?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Eval Code 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以搭配 Eval Code 使用,包括 GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等,都可在 TypingMind 中使用您自己的 API 密钥接入。

Eval Code AI 技能免费吗?

是的。该技能源自 Calibre-Labs 在 GitHub 上以 MIT 许可证发布的项目。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇