Skip to main content
This guide shows you how to use EvaluationLogger to record predictions and scores from your existing Python or TypeScript code, so you can evaluate model performance in Weave without first defining a full dataset and scorer suite. Use this approach when your dataset or scorers aren’t defined upfront, or when you need to log evaluation data incrementally as your workflow runs. In contrast to the standard Evaluation object, which requires a predefined Dataset and list of Scorer objects, the EvaluationLogger lets you log individual predictions and their associated scores incrementally as they become available.
Prefer a more structured evaluation?If you prefer a more opinionated evaluation framework with predefined datasets and scorers, see the standard Evaluation framework.The EvaluationLogger offers flexibility while the standard framework offers structure and guidance.

Basic workflow

Following these steps records a complete evaluation in Weave, with per-prediction scores and an aggregated summary that you can review in the Weave UI.
  1. Initialize the logger: Create an instance of EvaluationLogger, optionally providing metadata about the model and dataset. Weave uses defaults if omitted.
    To capture token usage and cost for LLM calls (for example, OpenAI), initialize EvaluationLogger before any LLM invocations. If you call your LLM first and then log predictions afterward, Weave doesn’t capture token and cost data.
  2. Log predictions: Call log_prediction() for each input and output pair from your system.
  3. Log scores: Use the returned ScoreLogger to log_score() for the prediction. Multiple scores per prediction are supported.
  4. Finish prediction: Always call finish() after logging scores for a prediction to finalize it.
  5. Log summary: After all predictions are processed, call log_summary() to aggregate scores and add optional custom metrics.
After calling finish() on a prediction, no more scores can be logged for it.
For a Python example that demonstrates this workflow, see the Basic example. If the output and all scores are available at once, Python users can combine steps 2 through 4 into a single call using log_example().

Basic example

The following example shows how to use EvaluationLogger to log predictions and scores inline with your existing code. Replace [YOUR-TEAM]/[YOUR-PROJECT] with your W&B entity and project.
The user_model function is defined and applied to a list of inputs. For each example:
  • The input and output are logged using log_prediction.
  • A correctness score (correctness_score) is logged through log_score.
  • finish() finalizes logging for that prediction.
Finally, log_summary records any aggregate metrics and triggers automatic score summarization in Weave.

Simplified logging with log_example()

Use log_example() to log inputs, an output, and scores in a single call. This convenience method combines log_prediction(), log_score(), and finish() into one step, and it’s useful when you already have the inputs, model outputs, and scores ready to log, such as during batch or offline evaluations.
The previous log_example() call is equivalent to:
log_example() is not available for the Weave TypeScript SDK. TypeScript users should use the logPrediction() and logScore() pattern shown in the basic example.

Advanced usage

The EvaluationLogger offers flexible patterns beyond the basic workflow to accommodate more complex evaluation scenarios. The following sections describe advanced techniques, including how to use context managers for automatic resource management, link agent traces to evaluation rows, separate model execution from logging, work with rich media data, and compare multiple model evaluations side by side.

Use context managers

The EvaluationLogger supports context managers (with statements) for both predictions and scores. This can provide cleaner code, automatic resource cleanup, and better tracking of nested operations like LLM judge calls. Using with statements in this context provides:
  • Automatic finish() calls when exiting the context.
  • Better token and cost tracking for nested LLM calls.
  • Setting output after model execution within the prediction context.
This pattern ensures that all nested operations are tracked and attributed to the parent prediction, giving you accurate token usage and cost data in the Weave UI.
In Python, keep each traced agent call inside its log_prediction() context. EvaluationLogger sets the evaluation run, example, and trial metadata on spans created in that context, and Weave uses that metadata to link the trace to its evaluation result.
Automatic evaluation-to-agent span linking is available only in Python. Neither the TypeScript EvaluationLogger nor Evaluation.evaluate() creates an active evaluation scope that links agent spans. In TypeScript, you can link a span only by setting the OTel attributes described in this section directly, and only when both Call IDs are already available.
The following example uses the OpenAI Agents SDK. The same pattern applies to other agent frameworks that Weave traces. Replace [YOUR-TEAM]/[YOUR-PROJECT] with your W&B entity and project.
If the agent runs before the prediction context starts or after it finishes, Weave records the trace but doesn’t link it to the evaluation result. Weave links a trace to its evaluation result automatically when the agent runs inside the log_prediction() context and a Weave integration traces it, as in the preceding code example. Otherwise, you set the two linking IDs on the agent spans yourself. How you do this depends on where the spans are created:
  • Same process, your own instrumentation: Set the attributes directly on each span.
  • A separate service: Send both IDs to that service, then set them on the spans it creates.
When spans are created inside the log_prediction() context, the EvaluationLogger sets all the attributes automatically. However, if you send spans with your own OpenTelemetry (OTel) instrumentation, you must set the attributes directly on each span that you want to link. You can set the following attributes for evaluations: Send the span to the same Weave project as the evaluation through the /agents/otel/v1/traces endpoint. OTel span attributes don’t propagate from parent spans to child spans, so set the attributes on every span that you want to link. For more information about the endpoint: Only weave.eval.run_id and weave.eval.predict_and_score_call_id establish the evaluation and result links. The row digest, example ID, trial index, kind, and evaluation name add context and support filtering, but don’t create a link by themselves. Use Weave Call IDs for the two linking attributes, not OTel trace or span IDs. You can obtain both IDs from the evaluation results query API. Each evaluation in the response has an evaluation_call_id, and each trial has a predict_and_score_call_id. The following examples assume that span is the OTel span for the agent operation. Replace each bracketed value with metadata from the evaluation run and result that the span belongs to. The TypeScript example works because it sets the OTel attributes directly rather than relying on a prediction scope. Use it only when both Call IDs are already available.
When your agent runs as a separate service, the evaluation process and the agent don’t share memory: Weave can’t set the linking attributes automatically, and you can’t reach the agent’s span objects directly. Instead, get both Call IDs in the evaluation process, send them to the service, and set them on the spans created there. This distributed EvaluationLogger pattern is Python-only.
Entering the log_prediction() context creates the Evaluation.predict_and_score call before the context body runs. The context yields a ScoreLogger (bound to prediction in the following example) that exposes both Call IDs. Keep the context open until the service returns so that you can log its output and scores on the same evaluation result.In the evaluation process, replace [AGENT-SERVICE-URL] with the endpoint that runs your agent, and replace [YOUR-TEAM]/[YOUR-PROJECT] as well:
In the agent service, copy the received attributes onto every agent span that you want to associate with the result. The following function demonstrates the receiving side with a raw OTel span. Configure the service to export spans to the same [YOUR-TEAM]/[YOUR-PROJECT] as the evaluation.
The wrapper span in this example is linked to the evaluation result. If the agent framework creates additional spans, copy eval_context onto those spans as well. OTel doesn’t inherit span attributes from the wrapper.

View linked agent spans from your evaluations

To inspect linked spans in the Weave UI:
  1. Navigate to wandb.ai.
  2. In the Weave sidebar menu, click Evals.
  3. Select your evaluation run.
  4. In the evaluation detail panel that opens, in the Evaluation tab, click View spans. This opens the Agents page with the Spans tab filtered to that evaluation.
When you pass raw datasets as inputs to log_prediction, Weave reimports the data with every evaluation run. This stores duplicate data, which can waste space if the dataset is large or if many evaluations reuse it. To avoid this duplication, publish your dataset to Weave before running any evaluations, then pass the published dataset’s rows as inputs. Weave resolves references to published rows using internal references instead of reimporting the data. This technique gives you the same linked experience as the standard Evaluation framework, where each prediction links back to a specific dataset row in the Weave UI. The following example publishes a dataset, links it in the EvaluationLogger, and retrieves and iterates over it like any other dataset.

Get outputs before logging

You can first compute your model outputs, then separately log predictions and scores. This separates evaluation and logging logic, which can make code easier to test and maintain when different parts of your system handle prediction generation and scoring.

Log rich media

Inputs, outputs, and scores can include rich media such as images, videos, audio, or structured tables. Logging rich media lets you inspect the actual content alongside scores in the Weave UI, which is helpful for qualitative analysis of multimodal models. Pass a dict or media object into the log_prediction or log_score methods.

Log and compare multiple evaluations

With EvaluationLogger, you can log and compare multiple evaluations side by side in the Weave UI. This is useful for assessing how different models perform on the same dataset.
  1. Run the following code sample.
  2. In the Weave UI, open the Evals tab.
  3. Select the evaluations that you want to compare.
  4. Click Compare. In the Compare view, you can:
    • Choose which evaluations to add or remove.
    • Choose which metrics to show or hide.
    • Page through specific examples to see how different models performed for the same input on a given dataset.
For more information about comparisons, see Comparisons.
Evals tab showing a list of evaluation runs
Comparison view showing metrics across multiple evaluation runs

Usage tips

The following tips help you get the most out of EvaluationLogger:
  • Call finish() promptly after each prediction.
  • Use log_summary to capture metrics not tied to single predictions (for example, overall latency).
  • Rich media logging is useful for qualitative analysis.