LLM output is free text, so you can't `assertEquals`. How do you test a feature that uses an LLM?
Short answer
Split it in two: the code around the LLM gets ordinary unit tests with a mocked model; prompt + model behavior is measured as a pass rate on a golden set of 100–300 cases, and the merge gate compares to the version in production, not to 100%.
3 points to say:
- Code around the LLM (JSON parsing, errors, timeouts): unit tests with a mocked model; behavior: pass rate on the golden set.
- The golden set comes from real logs, incidents and edge cases; answers are human-reviewed.
- Check cheap to expensive: hard checks → reference match → judge → human spot checks; read results per slice.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.