- CI/CD pipelines: Implement quality gates that fail builds if evaluation scores drop below a threshold.
- Local debugging: Inspect and analyze results without API calls.
- Custom aggregations: Calculate metrics and statistics using your own logic.
- Integration testing: Use evaluation results to gate merges or deployments.
Client.evaluate() response.
This page focuses on processing results programmatically while still uploading them to LangSmith.If you want to run evaluations locally without recording anything to LangSmith (for quick testing or validation), refer to Run an evaluation locally which uses
upload_results=False.Iterate over evaluation results
Theevaluate() function returns an iterator when called with blocking=False. This allows you to process results as they’re produced:
Understand the result structure
Each result in the iterator contains:-
result["run"]: The execution of your target function.result["run"].inputs: The inputs from your dataset example.result["run"].outputs: The outputs produced by your target function.result["run"].id: The unique ID for this run.
-
result["evaluation_results"]["results"]: A list ofEvaluationResultobjects, one per evaluator.key: The metric name (from your evaluator’s return value).score: The numeric score (typically 0-1 or boolean).comment: Optional explanatory text.source_run_id: The ID of the evaluator run.
-
result["example"]: The dataset example that was evaluated.result["example"].inputs: The input values.result["example"].outputs: The reference outputs (if any).
Example: Implement a quality gate
This example shows how to use evaluation results to pass or fail a CI/CD build automatically based on quality thresholds. The script iterates through results, calculates an average accuracy score, and exits with a non-zero status code if the accuracy falls below 85%. This ensures that you can deploy code changes that meet quality standards.Example: Collect results for analysis
Sometimes you may want to collect all results first before processing them. This is useful when you need to perform operations that require the full dataset (like calculating percentiles, sorting by score, or generating summary reports). Collecting results separately also prevents your output from being mixed with the logging fromevaluate().
Related
- Evaluate your LLM application
- Run an evaluation locally
- Fetch performance metrics from an experiment