Project | AI & LLM
Testing an LLM Feature (Claude)
An HR policy assistant on Claude and the harness that decides whether it can ship: structured replies, deterministic checks for facts, citations, a canary and colleagues' data, a calibrated groundedness judge, pass rates per area, and 168 tests of the harness itself, including a run on hand-written answers with planted leaks that the harness must catch.
CI replayed hand-written samples with planted flaws; no live model result is claimed.
Evidence checked 22 Nov 2026 | CI run #36 (hand-written sample answers)
On this page
Problem and purpose
Shows how to test a feature whose output is phrased differently every time, varies between runs and can be talked into misbehaving. The companion project uses AI to write tests; this one tests an AI feature, and tests the tests: the eval data, every check and the judge are verified before any model result is trusted.
Architecture
evals/cases.json (35 cases x 3 samples)
│
assistant answer ──► checks: outcome · facts · citations · canary · colleagues' dates ──► fail
│ pass
▼
LLM judge (groundedness) ◄── trusted only after calibration on 16 hand-labelled answers (min 90%)
▼
pass rate per tag vs threshold (injection, data leaks, stale context: 100%) ──► target/eval/report.mdTechnology and tools
| Area | Tools |
|---|---|
| Language | Java 21, Maven wrapper |
| Feature | LeaveDesk HR assistant on Claude Opus 5.5 through the Anthropic Java SDK: structured reply (answer, outcome, cited sections), fictional policy, minimal per-user context |
| Eval | golden set in JSON, deterministic checks, LLM-as-judge for groundedness with a calibration set, per-tag thresholds, Markdown report |
| Tests | TestNG: 168 harness tests with a scripted stub model and with hand-written samples; the eval as a TestNG suite with one test per threshold |
| CI | GitHub Actions: harness tests on every push, the eval on hand-written samples with planted flaws, the eval replayed from recordings, all without an API key |
Engineering decisions and approach
- Testability starts in the feature: a structured reply makes outcome and citations exact checks
- A fictional policy, so the model cannot answer from general knowledge and the eval shows whether it reads its source
- The assistant never receives colleagues' data; the leak check looks for their real dates in four formats
- A canary string in the system prompt makes instruction leaks detectable with a substring check
- Cheap deterministic checks first; the judge is only paid for answers that already passed them
- The eval data is tested: every hand-written reference answer must pass, and a refuse-everything model cannot pass the set
Test scope and execution approach
Project-specific checks and execution details documented in the repository:
- Seven areas: policy facts, own data, questions the policy does not answer, out of scope, prompt injection, data leaks, and stale context (an outdated answer already in the conversation must not be repeated)
- Injection cases include a fake HR notice where the right behaviour is to answer correctly, not to refuse
- Judge calibration with subtle wrong answers (right number, wrong deadline; wrong rounding); a judge that approves everything scores 50% and is rejected
- Report with pass rates per area, flaky cases, failures with reasons, judge agreement, latency percentiles and cost
- Recorded answers keyed on model, prompt, policy, question and sample, replayed in CI
- Design notes and 76 interview questions on testing LLM features, linked to the code (Markdown + PDF)
Results with dated evidence
Recorded CI replay
CI run #36 (hand-written sample answers)
CI replayed hand-written samples with planted flaws; no live model result is claimed.
Evidence checked: | Open dated evidence
Evidence explorer
Static screenshots are labelled as images; dated workflow links identify the execution evidence and its check date.
Static material from the public repository. The linked verification record was checked 2026-11-22; that date is not a screenshot capture date.
Dated workflow record
Evidence checked 2026-11-22. Open CI run #36 (hand-written sample answers)
Representative failure evidence
CI replay cases include planted rule violations, data leaks and incorrect facts to exercise failure detection.
Local setup and execution
mvnw.cmd test :: 168 harness tests, no key needed
llm ask alice How many days do I have left?
llm eval :: golden set + calibration (needs ANTHROPIC_API_KEY or recordings)Workflow and reports
Known limitations
- 35 cases is a starting set; production use needs cases from real questions
- The judge checks groundedness only, not tone or helpfulness; indirect injection through documents is not covered yet
- CI uses hand-written examples with planted flaws; no live model pass rate is claimed.