LLM evals are the difference between an AI feature that demos well and one you can ship with a straight face: a repeatable harness that runs your prompt and model against a fixed set of inputs, scores the outputs, and fails the build when quality regresses. In Rails, that harness is just RSpec (or a small rake task) plus your existing CI — no special platform required.
This guide shows how to build one: picking the golden set, three kinds of scoring, putting it in CI, and the traps that make evals useless.
Why eyeballing doesn’t scale
“Looks good to me” works on the day the feature launches, once. It does not work on the day you change the prompt for latency, swap Claude for OpenAI, or upgrade the SDK (RubyLLM is at 2.2.0 as of November 2026). Every one of those can silently flip behavior on the inputs you never re-checked. Evals convert “vibes” into a number you can put in a pull request.
Step 1: Build the golden set
An eval set is 20–50 representative inputs with known-good reference behavior. Sources, in order of value:
- Real support tickets / user questions (sanitized) — the distribution you actually serve.
- Failure cases you already hit — every “the AI said X but should have said Y” is a future regression test.
- Adversarial inputs — empty input, 10k-word input, injection attempts, languages you don’t serve.
Store them as YAML fixtures in the repo:
# spec/fixtures/evals/rag_answers.yml
- id: refund_policy_basic
input: "How do I get a refund for a cancelled order?"
must_include: ["14 days", "order number"]
must_not_include: ["chargeback"]You do not need perfect reference answers — many good evals only constrain properties, not exact wording.
Step 2: Three kinds of scoring
Use the cheapest check that catches the failure class:
- Deterministic assertions —
must_include, regex, JSON schema validation. Fast, free, brittle to wording changes. Use for facts that must appear. - Model-graded scoring (“LLM as judge”) — a second model scores the answer against a rubric (“Is the answer grounded in the retrieved context? 1–5”). Handles paraphrase; costs money per call; calibrate it against 20 hand-scored examples first.
- Human spot-checks — a weekly 30-minute review of sampled outputs. Not CI-grade, but it catches what automated scoring misses.
# spec/evals/rag_eval_spec.rb
RSpec.describe "RAG answer quality", type: :eval do
eval_set = YAML.load_file("spec/fixtures/evals/rag_answers.yml")
eval_set.each do |example|
it "handles #{example['id']}" do
answer = RagAnswerer.call(example['input'])
expect(example['must_include'] || []).each do |term|
expect(answer.downcase).to include(term.downcase)
end
(example['must_not_include'] || []).each do |term|
expect(answer.downcase).not_to include(term.downcase)
end
end
end
endStep 3: Gate CI, don’t gate every commit
Running 50 model calls on every push is slow and expensive. A workable split:
- PR-level: deterministic assertions only (schema, must_include), on a 10-case smoke set. Cheap enough for CI.
- Nightly / pre-release: the full golden set, including model-graded scoring and latency/cost recording.
- Weekly: human review of sampled production outputs.
Put the numbers in a file (or your eval provider of choice) so trend lines survive model upgrades — that’s how you catch the slow drift a one-off launch review never sees.
Step 4: Measure what the business cares about
Accuracy is necessary, not sufficient. Track, per release:
- Task success rate (did the agent complete the action?)
- Groundedness (answer supported by retrieved context?)
- p50/p95 latency and cost per request
- Escalation rate to humans — rising escalations after a prompt change is a regression even if accuracy looks flat
The traps that make evals useless
- Grading with the same model that answers without calibration — it inflates its own homework.
- Golden sets with no adversarial inputs — your average case improves while your injection handling collapses.
- Evals only at launch — prompts and SDKs drift; a suite that ran once proves nothing today.
- Overfitting to the set — models and prompts can be gamed to the fixture; rotate cases and keep some held out.
- No owner — evals nobody looks at are ceremony. Put the nightly score in the team’s Slack or dashboard.
I build eval harnesses as part of AI feature work — see my guide to AI integration in Rails and Rails pgvector guide for the retrieval side of the house.
Doing this on your Rails app
Start with 20 cases from real tickets, one deterministic assertion each, in CI as a smoke set. That alone will catch most silent regressions. If you want the full harness — golden sets, model-graded scoring and dashboards — send me a short brief; it’s part of what I build in AI software development for Rails.
Conclusion
Start with 20 real tickets, one assertion each, in CI — that alone turns model upgrades from a leap of faith into a diff you can read. When you want the full harness with model-graded scoring and trend tracking, send me a short brief.
Frequently asked questions
Do I need a special eval platform?
No. RSpec plus a YAML fixture and an optional judge model is enough to start. Platforms help at scale — many teams are well served by plain Rails and CI for months first.
How many cases do I need?
20–50 well-chosen cases beat 5,000 lazy ones. Cover the common paths, your worst past failures, and hostile input.
How do I judge “grounded in context” automatically?
A second (usually larger) model scores against a rubric. Validate it against 20 hand-scored examples and watch its agreement rate; discard judges that don’t correlate with you.
What about non-deterministic outputs?
Set temperature low for evals, and assert properties (contains, schema, source ids) rather than exact strings unless the output is meant to be templated.
Will evals slow down our pipeline?
They shouldn’t block every commit. Smoke set on PRs, full set nightly. Typical wall-clock cost is minutes, not hours.
How often do evals need maintenance?
Monthly, plus whenever a failure is reported. The golden set is a living document, not a launch artifact.


