Section 5: AI Evaluation, Observability, and Monitoring
Traditional software is deterministic; LLM outputs are probabilistic and context-sensitive. Combine deterministic unit tests for your application code with systematic behavioral evaluations ("evals") for the AI layer.
5.1 Four Evaluation Layers
| Evaluation Layer | What It Checks | Example Metrics / Assertions |
|---|---|---|
| Deterministic & Schema | Valid JSON, allowed tool names, citation IDs exist, no forbidden regex/PII | 100% schema parse rate; 0 unauthorized tool calls |
| Retrieval Quality | Did search surface the right chunks before generation? | Recall@5, MRR, NDCG, ACL filter leak rate = 0% |
| Task & Answer Quality | Is the answer grounded, accurate, complete, and properly abstaining? | Faithfulness, citation accuracy, task completion rate |
| Operational & Safety | Speed, unit economics, injection resilience, policy compliance | P95 latency, tokens/request, jailbreak block rate |
5.2 Golden Datasets, Failure Analysis, and LLM-as-a-Judge
- Golden Datasets: Start with 30–50 realistic examples covering common queries, edge cases, unanswerable questions (testing abstention), and adversarial inputs. Version datasets alongside prompts in Git, expand them from production failures, and keep a held-out split to avoid overfitting.
- Failure Analysis (Error Taxonomy): Review failed traces manually and tag root causes—e.g.,
stale_doc,missed_chunk,wrong_tool_args,hallucinated_citation. Turn every production incident into a permanent regression test. - LLM-as-a-Judge: Using a strong LLM with a clear rubric scales well, but judges exhibit position bias, verbosity bias, and variance. Calibrate judge prompts against human labels, use binary pass/fail or tightly anchored rubrics instead of vague 1–10 scales, and always pair judges with deterministic checks.
5.3 Observability, Telemetry, and Platform Categories
Treat every agent run as a distributed trace capturing prompt/model versions, retrieved document IDs and scores, tool inputs/outputs, token usage, latency per span, and error states. Redact PII and secrets before telemetry leaves your boundary.
- Framework-Native & AI Tracing Platforms: e.g., LangSmith, Langfuse (open-source/self-hostable), Arize Phoenix, Braintrust—focused on prompt versioning, trace visualization, and dataset evals.
- OpenTelemetry & General APM Suites: e.g., Datadog, Honeycomb, Grafana with OpenTelemetry GenAI semantic conventions—ideal for unifying AI traces with infrastructure alerts.
- Selection Criteria: Prioritize data residency/self-hosting options, PII redaction hooks, low-overhead async logging, CI/CD eval gating, and open standards to avoid lock-in.