Skip to main content
Prerequisites:
  • Python 3.10+
  • An API key for an LLM provider (e.g., OpenAI, Anthropic, Google)
This guide demonstrates how to write a robust, statistical, end-to-end test for a conversational AI chatbot with SigmaEval and pytest. Weโ€™ll start by building a simple AI assistant to have an application to test. By the end, you will have a complete, runnable example that you can adapt for your own projects.

Installation

First, install the necessary libraries from PyPI. We recommend creating a virtual environment to avoid dependency conflicts.
You will also need to set your API key for the LLM provider you wish to use. SigmaEval supports 100+ LLM providers via LiteLLM, including OpenAI, Anthropic, Google, and local models via Ollama.
The code in this tutorial uses Gemini as the LLM provider. If you want to use a different provider replace the model name in the code with the name of the model you want to use. See the LiteLLM documentation for more information.

Step 1: Build a Simple AI Assistant

First, letโ€™s create a simple, but complete, AI application that we can test. This assistant is for an e-commerce store and uses a system prompt to define its capabilities. Create a file named app.py:
app.py

Step 2: Write Your First Evaluation with Pytest

Now that we have an application, we can write a test for it using SigmaEval and pytest. This test will verify that our assistant not only provides the correct information but also does so in a timely manner. Create a file named test_app.py in the same directory:
test_app.py

Step 3: Run the Test and Interpret the Results

With your app.py and test_app.py files in place, you can run the evaluation from your terminal.
terminal
When you run the test, SigmaEval will simulate 10 conversations with your bot, have an AI Judge score each one against both of your expectations, and then print a summary of the results. The final output will look something like this:
This output confirms that the test passed because both the behavioral (expect_behavior) and the performance (expect_metric) expectations were met with statistical confidence.

Next Steps

Now that youโ€™ve run your first end-to-end evaluation, you can start applying SigmaEval to your own Gen AI applications. Try modifying the system prompt in app.py or the expectations in test_app.py to see how the results change.