> ## Documentation Index
> Fetch the complete documentation index at: https://docs.honeyhive.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Client-Side Evaluations

> Learn how to log external evaluation results (metrics) with your trace.

export const enrichmentType_4 = "Metrics"

export const paramName_3 = "metrics"

export const enrichmentType_3 = "Metrics"

export const paramName_2 = "metrics"

export const enrichmentType_2 = "Metrics"

export const paramName_1 = "metrics"

export const enrichmentType_1 = "Metrics"

export const paramName_0 = "metrics"

export const enrichmentType_0 = "Metrics"

## Introduction

Client-side evaluations allow you to log external evaluation results (metrics) with your trace.

### Prerequisites

You have already set tracing for your code as [described in our quickstart guide](/introduction/quickstart).

## Setting {enrichmentType_0}

You can set {enrichmentType_0} on both the trace level or the span level. If the {enrichmentType_0} applies to the entire trace, then set it on the trace level. If the {enrichmentType_0} applies to a specific span, then set it on the span level. For more details, refer to the [enrich traces](/tracing/enrich-traces) documentation.

<Tabs>
  <Tab title="Python">
    <Tabs>
      <Tab title="Setting Metrics on Trace Level">
        In Python, you can use the `enrich_session` function to set {enrichmentType_1} on the trace level.

        To pass {enrichmentType_1} to HoneyHive, pass it to the {paramName_0} param in the `enrich_session` function. This function is used to enrich the session with additional information. Remember that `enrich_session` will update, not overwrite, the existing {paramName_0} object on the trace.

        Read more about the `enrich_session` function in the [Python SDK reference](/sdk-reference/python-tracer-ref#enrich-session).

        Here's an example of how to set {enrichmentType_1} on the trace level in Python:

        ```python Python theme={null}
        from honeyhive import HoneyHiveTracer, enrich_session

        HoneyHiveTracer.init(
          api_key="my-api-key",
          project="my-project",
        )

        # ...

        enrich_session(metrics={
          "json_validated": True,
          "num_actions": 10,
          # any other custom fields and values as you need
          "step_evals": [
            {
              "invalid_grammar": False,
              "unable_to_locate_UI": True
            }
          ],
        })
        ```
      </Tab>

      <Tab title="Setting Metrics on Span Level">
        In Python, you can use the `enrich_span` function to set {enrichmentType_3} on the span level.

        To pass {enrichmentType_3} to HoneyHive, pass it to the {paramName_2} param in the `enrich_span` function. This function is used to enrich the span with additional information. Remember that `enrich_span` will update, not overwrite, the existing {paramName_2} object linked to the span.

        Read more about the `enrich_span` function in the [Python SDK reference](/sdk-reference/python-tracer-ref#enrich-span).

        Here's an example of how to set {enrichmentType_3} on the span level in Python:

        ```python Python theme={null}
        from honeyhive import HoneyHiveTracer, trace, enrich_span

        HoneyHiveTracer.init(
          api_key="my-api-key",
          project="my-project",
        )

        # ...

        @trace
        def my_function(input, offline_eval_score):
            # ...

            enrich_span(metrics={
              "json_validated": True,
              "num_actions": 10,
              "offline_eval_score": offline_eval_score,
              # any other custom fields and values as you need
              "step_evals": [
                {
                  "invalid_grammar": False,
                  "unable_to_locate_UI": True
                }
              ],
            })

            # ...

            return response

        # ...

        ```
      </Tab>
    </Tabs>
  </Tab>

  <Tab title="TypeScript">
    <Tabs>
      <Tab title="Setting Metrics on Trace Level">
        In TypeScript, you can use the `tracer.enrichSession` function to set {enrichmentType_2} on the trace level.

        To pass {enrichmentType_2} to HoneyHive, pass it to the {paramName_1} param in the `tracer.enrichSession` function. This function is used to enrich the session with additional information. Remember that `tracer.enrichSession` will update, not overwrite, the existing {paramName_1} object linked to the trace.

        Read more about the `tracer.enrichSession` function in the [TypeScript SDK reference](/sdk-reference/typescript-tracer-ref#enrichsession).

        Here's an example of how to set {enrichmentType_2} on the trace level in TypeScript:

        ```typescript TypeScript theme={null}
        import { HoneyHiveTracer } from "honeyhive";

        const tracer = await HoneyHiveTracer.init({
          apiKey: "my-api-key",
          project: "my-project",
        });

        // ...

        tracer.enrichSession({
          metrics: {
            "json_validated": true,
            "num_actions": 10,
            // any other custom fields and values as you need
            "step_evals": [
              {
                "invalid_grammar": false,
                "unable_to_locate_UI": true
              }
            ],
          }
        })
        ```
      </Tab>

      <Tab title="Setting Metrics on Span Level">
        In TypeScript, you can use the `tracer.enrichSpan` function to set {enrichmentType_4} on the span level.

        To pass {enrichmentType_4} to HoneyHive, pass it to the {paramName_3} param in the `tracer.enrichSpan` function. This function is used to enrich the span with additional information. Remember that `tracer.enrichSpan` will update, not overwrite, the existing {paramName_3} object linked to the span.

        Read more about the `tracer.enrichSpan` function in the [TypeScript SDK reference](/sdk-reference/typescript-tracer-ref#enrichspan).

        Here's an example of how to set {enrichmentType_4} on the span level in TypeScript:

        ```typescript TypeScript theme={null}
        import { HoneyHiveTracer } from "honeyhive";

        const tracer = await HoneyHiveTracer.init({
          apiKey: "my-api-key",
          project: "my-project",
        });

        // ...

        const myTracedFunction = tracer.traceFunction()(function (param1, param2) {

            // span enrichment
            tracer.enrichSpan({
              metrics: {
                "json_validated": true,
                "num_actions": 10,
                // any other custom fields and values as you need
                "step_evals": [
                  {
                    "invalid_grammar": false,
                    "unable_to_locate_UI": true
                  }
                ],
              }
            });

            // Your function code here
            return `Result with ${param1} and ${param2}`;
        });

        // ...
        ```
      </Tab>
    </Tabs>
  </Tab>
</Tabs>

## Concepts

If you are defining any evaluators in your application execution i.e. client-side, you can add the resulting metrics to any trace or span in HoneyHive for monitoring and analysis.

<Tip>Most guardrails (eg: format, safety, PII, etc.) are ideal to compute client-side at execution time instead of server-side in HoneyHive post-ingestion.</Tip>

### What are evaluators?

Evaluators are tests (code or LLM based) that compute a score/metric to measure the quality of inputs and/or outputs for your application or specific steps within it.

They can be computed and instrumented within your application runtime (client-side) or computed in our platform (server-side) post-ingestion.

<Note>Evaluators computed client-side are not overwritten by server-side evaluators of the same name.</Note>

## Return Types

We accept all primary data types as evaluator metrics. This includes:

| Return Type | Available Measurements                    | Notes                         | Uses                                     |
| ----------- | ----------------------------------------- | ----------------------------- | ---------------------------------------- |
| Boolean     | Percentage True/False                     | -                             | Evaluations                              |
| Number      | Sum, Avg, Median, Min, Max, P95, P98, P99 | -                             | Evaluations                              |
| String      | -                                         | Used for filters and group by | Classification, feature extraction, etc. |

For complex data types, we allow you to drill down to the nested fields or specific positions in the array.

So, for example, if you pass metrics like:

```json theme={null}
{
  "step_evals": [
    {
      "invalid_grammar": true,
      "user_interevened": true
    },
    {
      "invalid_grammar": false,
      "unable_to_locate_UI": true
    }
  ],
  "trajectory_eval": {
    "overall": 5,
    "clarified_user_intent": "yes"
  }
}
```

You can chart `metrics.step_evals.0.user_intervened` as a boolean field or `trajectory_eval.overall` as a numeric field.

<Note>**Nesting Limitations:** For complex data types like objects and arrays, we allow max 5 levels of nested objects and max 2 levels of nested arrays.</Note>

## Learn more

<CardGroup cols={2}>
  <Card title="Charting metrics" icon="rectangle-terminal" href="/monitoring/charts">
    Learn how to chart metrics from your traces
  </Card>

  <Card title="Setup server-side code evaluators" icon="rectangle-terminal" href="/evaluators/python">
    Learn how to compute metrics server-side over your logs via code
  </Card>

  <Card title="Setup server-side LLM evaluators" icon="rectangle-terminal" href="/evaluators/llm">
    Learn how to compute metrics server-side over your logs via a LLM
  </Card>

  <Card title="Setup human annotations" icon="rectangle-terminal" href="/evaluators/human">
    Learn how to setup annotation for your logs via domain experts
  </Card>
</CardGroup>

## SDK Reference

Read more about the `enrich_session` function in the [Python SDK reference](/sdk-reference/python-tracer-ref#enrich-session).
