Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Workflow:Explodinggradients Ragas Prompt Evaluation And Iteration

From Leeroopedia


Knowledge Sources
Domains LLMs, Evaluation, Prompt_Engineering
Last Updated 2026-02-10 06:00 GMT

Overview

End-to-end process for evaluating and iteratively improving LLM prompts using Ragas experiments, custom metrics, and systematic A/B comparison.

Description

This workflow covers the systematic evaluation and improvement of LLM application prompts. It starts with defining an evaluation dataset and baseline metrics, runs experiments with the current prompt version, analyzes results to identify failure patterns, creates improved prompt versions, and re-evaluates to measure improvement. The Ragas experiment framework enables structured comparison across prompt versions with persistent result tracking. This supports both simple single-prompt evaluation (e.g., sentiment classification) and complex multi-step prompt workflows (e.g., customer support triage).

Usage

Execute this workflow when you need to objectively measure and improve the quality of prompts used in your LLM application. You should have a labeled evaluation dataset with expected outputs and a prompt that needs optimization. This is essential during prompt development, when migrating between LLM providers, or when prompt quality degrades after model updates.

Execution Steps

Step 1: Prepare the Evaluation Dataset

Create a labeled dataset with input samples and expected outputs or grading criteria. For classification tasks, include ground truth labels. For generation tasks, include reference outputs or evaluation rubrics. The dataset should cover representative examples from production usage.

Key considerations:

  • Use a Pydantic model to enforce schema consistency
  • Include diverse examples covering all expected output categories
  • For classification: include balanced representation of each class
  • For generation: include clear grading criteria or reference outputs

Step 2: Define Evaluation Metrics

Create metrics that capture the quality dimensions important for your prompt. For classification prompts, use discrete metrics (accuracy, per-class precision). For generation prompts, use numeric metrics or LLM-based judges. Multiple metrics can be combined to capture different quality aspects.

Key considerations:

  • @discrete_metric works well for classification accuracy measurement
  • DiscreteMetric with custom prompts enables LLM-as-judge evaluation
  • Multiple metrics can evaluate different aspects (accuracy, tone, completeness)
  • Metrics should align with production quality requirements

Step 3: Run Baseline Experiment

Run the first experiment with the current prompt version (v1) to establish a baseline. The experiment processes each dataset sample through the LLM with the current prompt, collects responses, and scores them using the defined metrics. Results are persisted for later comparison.

Key considerations:

  • Name experiments descriptively (e.g., "prompt_v1_baseline")
  • The @experiment decorator handles async execution and result collection
  • Baseline results serve as the reference point for measuring improvement
  • Examine per-sample results to understand failure patterns

Step 4: Analyze Failures and Improve the Prompt

Review baseline results to identify systematic failure patterns. Look for common misclassifications, missing information, or quality issues. Based on this analysis, create an improved prompt version that addresses the identified weaknesses. Common improvements include adding few-shot examples, clarifying instructions, adding edge case handling, and restructuring the prompt.

Key considerations:

  • Focus on the most common failure modes first
  • Adding few-shot examples often provides significant improvement
  • Clarifying ambiguous instructions reduces inconsistent outputs
  • Keep prompt changes targeted and measurable

Step 5: Run Comparison Experiment and Iterate

Run a new experiment with the improved prompt version (v2) using the same dataset and metrics. Compare results against the baseline to measure improvement. If quality targets are not met, analyze remaining failures and create further prompt iterations. Continue until the prompt meets production quality requirements.

Key considerations:

  • Use the same dataset and metrics for fair comparison
  • Compare aggregate scores and per-sample deltas
  • The CLI displays comparison tables with improvement indicators
  • Use version_experiment() to track prompt versions in git
  • Multiple iterations may be needed to reach quality targets

Execution Diagram

GitHub URL

Workflow Repository