Prompt
How do I set up recurring tests for answer engines?
Latest observation
A good setup for recurring tests on answer engines is to treat them like a regression test suite for model behavior, not just a one-off eval. Here’s a practical way to do it.
1) Define what you want to measure
Pick a small set of core metrics:
- Accuracy / correctness: Is the answer factually right?
- Completeness: Does it include the important points?
- Groundedness: Is it supported by the provided context or sources?
- Format compliance: Does it follow JSON, bullets, citation style, etc.?
- Safety / policy compliance: Does it avoid disallowed content?
- Consistency: Does it answer similarly across runs?
If you’re doing retrieval-augmented generation, split metrics into:
- Retrieval quality: Did it fetch the right sources?
- Generation quality: Did it use those sources correctly?
2) Build a benchmark set
Create a fixed test set of prompts that reflect your real traffic.
Include a mix of:
- Common user queries
- Edge cases
- Ambiguous questions
- Hard factual questions
- Questions with known correct answers
- Prompt-injection and adversarial cases
- Formatting-sensitive tasks
For each test item, store:
- Prompt
- Expected answer or rubric
- Source of truth
- Category/tag
- Severity/priority
- Optional reference context/docs
Keep this dataset versioned in Git or a similar system.
3) Decide how to score answers
Use a combination of automated and human scoring.
Automated scoring
Good for:
- Exact match or regex checks
- Structured outputs
- Citation presence
- JSON/schema validation
- Retrieval hit rate
- Factual checks against known answers
LLM-as-judge
Useful when answers are open-ended. Have a judge model score against a rubric like:
- Correctness: 1–5
- Completeness: 1–5
- Clarity: 1–5
- Hallucination risk: 1–5
Make the rubric explicit and stable so scores are comparable over time.
Human review
Use for:
- New test categories
- Borderline failures
- Periodic calibration of automated judges
4) Create a recurring test harness
Run tests on a schedule:
- On every code/model prompt change
- Nightly
- Weekly full regression
- Before deployment
Your harness should:
- Load the test set
- Call the answer engine with fixed settings
- Capture outputs, latency, token usage, and errors
- Score results
- Compare against baseline
- Alert on regressions
5) Track trends, not just pass/fail
Store historical results so you can see:
- Score over time
- Failure rate by category
- Latency changes
- Regression after a prompt/model/retrieval update
This helps you answer:
- “Did the new model improve factuality but hurt formatting?”
- “Did retrieval changes reduce hallucinations?”
- “Are failures concentrated in one domain?”
6) Use thresholds and gates
Define what blocks release:
- Overall score drops by > X%
- Specific critical category fails
- Any safety violation
- Latency exceeds target
- JSON/schema failure rate above threshold
Example:
- Must achieve ≥ 90% on critical factual questions
- Must be 100% valid JSON on structured outputs
- Must not regress more than 2 points in hallucination score
7) Include adversarial and drift tests
Recurring tests should catch failure modes that appear later:
- Prompt injection
- Changing docs / stale knowledge
- New product names or policies
- Ambiguous queries
- Long-context behavior
- Citation corruption
- Over-refusal or under-refusal
Refresh the benchmark periodically, but keep a stable core set for comparability.
8) Tooling options
You can implement this with:
- Python + pytest
- A small internal eval runner
- CI/CD pipelines (GitHub Actions, GitLab CI, etc.)
- Experiment tracking tools like:
- Weights & Biases
- MLflow
- LangSmith
- OpenAI eval frameworks or similar
- RAG eval tools
A simple setup is:
- Test cases in YAML/JSON
- A Python runner
- Output results to CSV/SQLite/Postgres
- Dashboard in Metabase/Grafana/Looker
9) Recommended minimal structure
A test case might look like:
{
"id": "billing_refund_001",
"category": "support",
"prompt": "How do I request a refund?",
"expected": {
"must_include": ["refund window", "contact support"],
"must_not_include": ["guaranteed approval"]
},
"rubric": {
"correctness": 5,
"completeness": 4
},
"critical": true
}
10) Start small
A practical rollout:
- Start with 20–50 high-value test cases
- Automate scoring for the easiest checks first
- Add LLM judge scoring later
- Review failures weekly
- Expand coverage over time
If you want, I can also give you:
- a sample YAML/JSON test suite,
- a Python eval runner, or
- a CI workflow for recurring answer-engine tests.