> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-zh.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 如何返回分类指标与数值指标

LangSmith 同时支持分类指标和数值指标，在编写自定义评估器时，您可以返回任意一种类型。

若要将评估器结果记录为数值指标，必须返回以下形式之一：

* （仅限 Python）`int`、`float` 或 `bool` 类型
* 形式为 `{"key": "metric_name", "score": int | float | bool}` 的字典

若要将评估器结果记录为分类指标，必须返回以下形式之一：

* （仅限 Python）`str` 类型
* 形式为 `{"key": "metric_name", "value": str | int | float | bool}` 的字典

以下是一些示例：

* Python：需要 `langsmith>=0.2.0`
* TypeScript：`langsmith@0.1.32` 及以上版本支持多分数返回

<CodeGroup>
  ```python Python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  def numerical_metric(inputs: dict, outputs: dict, reference_outputs: dict) -> float:
      # 评估逻辑...
      return 0.8
      # 等效写法
      # return {"score": 0.8}
      # 或
      # return {"key": "numerical_metric", "score": 0.8}

  def categorical_metric(inputs: dict, outputs: dict, reference_outputs: dict) -> str:
      # 评估逻辑...
      return "english"
      # 等效写法
      # return {"key": "categorical_metric", "score": "english"}
      # 或
      # return {"score": "english"}
  ```

  ```typescript TypeScript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  import type { Run, Example } from "langsmith/schemas";

  function numericalMetric(run: Run, example: Example) {
    // 在此处编写评估逻辑
    return { key: "numerical_metric", score: 0.8};
  }

  function categoricalMetric(run: Run, example: Example) {
    // 在此处编写评估逻辑
    return { key: "categorical_metric", value: "english"};
  }
  ```
</CodeGroup>

## 相关链接

* [在单个评估器中返回多个指标](/langsmith/multiple-scores)

***

<div className="source-links">
  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/i18n\zh-CN\langsmith\metric-type.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>

  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>
</div>
