November 2024
LLMs: time to stop coding blindly? TDD to the rescue!
How to test something you cannot predict: the tests written before the prompt, on a real chatbot project.
November 2024
How to test something you cannot predict: the tests written before the prompt, on a real chatbot project.
Tests on LLM features get skipped with one argument: you cannot test something you cannot predict. I took that argument to the room least likely to let it pass, about twenty testing specialists at the Soirée du Test Logiciel in Sophia Antipolis.
The talk starts with a small experiment: I asked ChatGPT for its favourite animal 1,000 times (dolphin wins by far). It ends on a real case from a client project at Orange Business, a chatbot for the citizens of a city, where the tests existed before the prompt did. They were written with Promptfoo and they run in GitLab CI.
The talk was given in French; this page is the English write-up.

Slide 1 / 29
Slide 1
Applying TDD to LLMs is often skipped, on the grounds that it is neither possible nor worth it. This talk shows how I do it anyway.
Slide 2
I am a generative AI solution architect at Orange Business, and at the time I was also finishing my apprenticeship at Polytech Nice Sophia.
Slide 3
A quick look at the room: about twenty testing specialists.
Slide 4
Two acronyms in the title, so let me define them first.
Slide 5
An LLM, a large language model, is a black box. Text, audio, images or video go in, and something comes out in the same kinds of formats.
Slide 6
TDD, test-driven development: write a failing test, make it pass, refactor. The test comes before the code.
Slide 7
Testing LLMs pays off in reliability, security, performance and cost. It also lets you benchmark several models against the same cases.
Slide 8
Because the inputs are infinite, and so are the outputs. Natural language has no finite list of cases, and the black box in the middle can answer anything.
Slide 9
A small experiment: I asked ChatGPT for its favourite animal 1,000 times, same prompt every time. Dolphin wins by far, cat and dog trail behind. Same question, different answers.
Slide 10
Then three phrasings of the same question: a plain one, a polite one, one written as an objective with rules. The distribution moves a lot. With one, dolphin dominates; with another, cat comes first.
Slide 11
Yet for a given prompt, the behaviour is stable. Prompt 1, called 100 times in 10 batches: dolphin stays around 80 to 90% every batch.
Slide 12
So how do you make sure it stays that way? The answer was in the name of the event: you test it.
Slide 13
The obvious objection: how do you test something you cannot predict?
Slide 14
Back to basics. A function and an input give an actual result, and you validate it against an expected result. Pass or fail.
Slide 15
The same five boxes work for an LLM. The function is either a direct call to a model, or a call to a process that uses a model somewhere inside.
Slide 16
The input has three parts: the user's request, the system prompt with the model settings, and external content injected into the prompt, like today's date.
Slide 17
The expected result is either free text or a structured format like JSON.
Slide 18
Validation follows from that. Free text needs metrics evaluated by another LLM acting as a judge. Structured output can be checked with deterministic metrics, like any other code.
Slide 19
A real case: a chatbot for the citizens of a city, built on a client project at Orange Business. A multi-agent system using several LLMs. I zoomed in on one node.
Slide 20
The feature, as a user story: get information about the events available at a given time. People ask for it in many different ways.
Slide 21
The node turns the request into a structured call: categories, a start and an end datetime. Writing it down raises the real questions: what is the evening? What if there is no date, no time, no detail at all?
Slide 22
For the tests I used Promptfoo, a kind of baby Pytest or Jest for prompts.
Slide 23
The config: the function under test, two versions of the system prompt, one test file per kind of date (precise, imprecise, relative, missing, impossible), and assertions on format first, then on content.
Slide 24
Each case is a user prompt with the categories and date range I expect back. These exist before the prompt does.
Slide 25
Only then the feature: a system prompt that always calls the events tool, with explicit rules for times of day, date formats and the list of categories.
Slide 26
Promptfoo runs every case against every prompt version and shows passes and failures side by side. The same view compares models.
Slide 27
And the tests run in GitLab CI with the rest of the code, before every deploy.
Slide 28
Testing LLMs is possible. It just isn't easy.
Slide 29
Thank you for listening.