Tekko

Language

Get in Touch →

Usually respond within 24 hours

Back to BlogAI & ML

EDD for RAG: Building Robust AI with Arize Phoenix and Giskard

7 min read
RAGLLMopsArize PhoenixGiskardAI Quality
EDD for RAG: Building Robust AI with Arize Phoenix and Giskard

The hardest part of moving a Retrieval-Augmented Generation (RAG) system from prototype to production isn't the vector database or the prompt engineering—it's the uncertainty. In traditional software, we have unit tests and deterministic outputs. In RAG, we have 'vibe checks.' We change a prompt or swap an embedding model, and we hope the output doesn't break.

This lack of rigor is why many AI projects stall in the 'demo' phase. To move beyond this, we need to adopt Evaluation-Driven Development (EDD). Much like Test-Driven Development (TDD) revolutionized backend engineering, EDD provides a framework for building AI applications where evaluation is not an afterthought, but the core driver of the development cycle.

In this guide, we will explore how to implement EDD using two powerful tools: Arize Phoenix for observability and evaluation tracing, and Giskard for automated scanning and unit testing.

The Shift to Evaluation-Driven Development (EDD)

In a standard RAG pipeline, a user's query is converted into an embedding, relevant documents are retrieved from a vector store, and an LLM generates a response based on those documents. Each step introduces a point of failure:

  1. Retrieval Failure: The system fetches irrelevant documents.
  2. Augmentation Failure: The context is correct, but the LLM ignores it.
  3. Generation Failure: The LLM hallucinates or produces toxic content.

EDD addresses these by mandating that every change to the pipeline must be validated against a set of quantitative metrics. Instead of asking 'Does this look okay?', we ask 'Does this improve our Faithfulness score by 5% without regressing on Context Precision?'

The Toolkit: Arize Phoenix and Giskard

To implement EDD, we need two types of tooling: Observability/Tracing and Automated Quality Assurance.

Arize Phoenix

Phoenix is an open-source observability library designed for LLM applications. It allows us to trace every step of our RAG pipeline, visualize the latent space of our embeddings, and run LLM-assisted evaluations (LLM-as-a-judge). It is particularly strong at identifying where in the 'trace' a hallucination occurred.

Giskard

Giskard is a specialized testing framework for ML models. It provides an automated 'scanner' that probes your RAG system for common vulnerabilities, such as hallucinations, bias, and performance bottlenecks. It allows us to turn these findings into concrete unit tests that can run in a CI/CD pipeline.

Step 1: Instrumenting the RAG Pipeline with Arize Phoenix

Before we can evaluate, we must observe. Phoenix uses the OpenInference standard to trace calls. If you are using frameworks like LlamaIndex or LangChain, integration is often just a few lines of code.

import phoenix as px from phoenix.trace.llama_index import LlamaIndexInstrumentor # Launch the Phoenix server to view traces session = px.launch_app() # Instrument your RAG framework LlamaIndexInstrumentor().instrument()

Once instrumented, every query to your RAG system is captured. You can see exactly what was retrieved, the prompt template used, and the raw LLM response. This data is the foundation of your evaluation dataset.

Step 2: Defining Key RAG Metrics

In EDD, we don't just look at 'accuracy.' We break it down into the 'RAG Triad':

  1. Context Relevance: Is the retrieved document actually useful for answering the query?
  2. Faithfulness (Groundedness): Is the answer derived only from the retrieved context, or did the LLM make it up?
  3. Answer Relevance: Does the answer actually address the user's question?

Using Arize Phoenix, we can run these evaluations using an 'evaluator' LLM (like GPT-4o) to score our traces. This transforms qualitative output into quantitative data.

from phoenix.evals import OpenAIModel, HallucinationEvaluator, run_evals # Define the evaluator model eval_model = OpenAIModel(model="gpt-4o") # Run a hallucination check on captured traces hallucination_evaluator = HallucinationEvaluator(eval_model) eval_results = run_evals( dataframe=px.active_session().get_spans_dataframe('retrieval'), evaluators=[hallucination_evaluator], provide_explanation=True )

Step 3: Automated Scanning with Giskard

While Phoenix is excellent for tracing and continuous monitoring, Giskard excels at the 'pre-deployment' phase. Giskard’s scanner can automatically generate hundreds of test cases to find edge cases where your RAG might fail.

To use Giskard, we wrap our RAG logic into a simple function and let the scanner do the work:

import giskard import pandas as pd def model_predict(df: pd.DataFrame): return [rag_pipeline.query(question) for question in df["question"]] giskard_model = giskard.Model( model=model_predict, model_type="text_generation", name="RAG_Support_Bot", description="A bot that answers technical questions based on internal documentation", feature_names=["question"] ) # Scan for hallucinations and vulnerabilities scan_results = giskard.scan(giskard_model)

The scan method doesn't just check for accuracy; it checks for robustness (changing a word shouldn't change the answer) and hallucination (asking a question not in the docs should result in 'I don't know').

Step 4: Building Automated Unit Tests

Once Giskard identifies a failure—for example, the model hallucinates when asked about 'deprecated APIs'—we can convert that specific failure into a permanent test case. This ensures that a future update to the prompt or the vector store doesn't re-introduce the bug.

# Create a test suite from the scan results test_suite = scan_results.generate_test_suite("My RAG Test Suite") # Run the suite results = test_suite.run()

This suite can be integrated into your GitHub Actions or GitLab CI. If a PR changes the RAG configuration and the faithfulness score drops below a threshold (e.g., 0.8), the build fails. This is the essence of EDD: the code is only as good as its ability to pass the evaluation.

Practical Example: Controlling Hallucinations

Let’s say you’re building a RAG for medical insurance policies. A hallucination here isn't just a bug; it's a liability.

With Phoenix, you might notice in your traces that when users ask about 'dental coverage,' the retriever pulls documents about 'vision coverage' because the embedding vectors are too close in latent space.

The EDD Workflow:

  1. Identify: Phoenix shows a low 'Context Relevance' score for dental queries.
  2. Test: Create a Giskard test case specifically for dental coverage questions.
  3. Fix: You decide to implement a Re-ranker (like Cohere) to improve retrieval precision.
  4. Verify: Re-run the Giskard test suite and Phoenix evals. If the 'Context Relevance' score improves and the test passes, you merge the code.

Advanced Strategy: The Golden Dataset

No EDD implementation is complete without a 'Golden Dataset'—a curated set of (Question, Context, Ground Truth Answer) triples that represent the 'perfect' behavior of your system.

You can use Arize Phoenix to export high-confidence traces as your initial Golden Dataset. Over time, as humans review and correct LLM outputs, this dataset grows. Giskard can then use this dataset to calculate RAGAS metrics (Retrieval-Augmented Generation Assessment) automatically during every deployment.

Overcoming the Cost of LLM-as-a-Judge

A common concern with EDD is the cost and latency of using an LLM (like GPT-4) to evaluate another LLM. To optimize this:

  1. Sample during Dev: Don't evaluate 1,000 traces on every save. Sample 50.
  2. Use Smaller Models: Use GPT-4o-mini or a fine-tuned Llama-3-8B for evaluation tasks. Phoenix supports any model that follows the OpenAI API format.
  3. Focus on the 'Failures': Use Giskard to identify the 5% of queries where the model is uncertain and only run heavy evaluations on those.

Conclusion: The Actionable Path Forward

Building RAG systems without evaluation is like flying a plane without an altimeter. You might feel like you're ascending, but you won't know you've stalled until you hit the ground. By implementing Evaluation-Driven Development with Arize Phoenix and Giskard, you replace intuition with engineering rigor.

Your immediate next steps:

  1. Instrument: Add Phoenix tracing to your existing RAG pipeline today to see what's actually happening under the hood.
  2. Scan: Run a Giskard scan against your current prompt to find hidden hallucinations.
  3. Baseline: Calculate your current 'Faithfulness' and 'Context Relevancy' scores. This is your baseline.
  4. Automate: Integrate a Giskard test suite into your CI/CD pipeline to ensure your RAG quality never regresses.

In the era of non-deterministic software, the developer who masters evaluation is the one who delivers production-ready AI.