Skip to content

Research: Evals & Guardrails for AI Agents

TL;DR

  • Build an agent that is measurably accurate and safely bounded. This guide covers datasets, offline evals, online monitoring, and runtime guardrails in one connected system.
  • Follow the real engineering order: understand the failure modes → build a dataset → measure offline → add runtime guardrails → monitor live traffic → feed failures back into your dataset.
  • Use agentic RAG as the worked example, not the limit. For coding, browser, research, or workflow agents, start with Agent Archetypes.
flowchart LR
    F["00 Foundations<br/>mental model + failure modes"] --> D["01 Datasets<br/>SME, synthetic, production"]
    D --> OFF["02 Offline evals<br/>end-to-end + component"]
    OFF --> G["04 Guardrails<br/>runtime enforcement"]
    G --> ON["03 Online evals<br/>+ observability"]
    ON -->|"traces, feedback, failures"| D
    DF["05 Decision framework<br/>what to do, in what order"] -.-> D
    DF -.-> OFF
    DF -.-> G
    DF -.-> ON
    T["06 Tooling"] -.-> OFF
    T -.-> G
    T -.-> ON

Start here (pick your goal)

If you are… Read this first Read this second
New to evals and guardrails The Evals & Guardrails Map Why Evals and Guardrails → Failure Modes
Building your first RAG or agent prototype Implementation Playbook Dataset Strategy → End-to-End RAG Evals
Building a coding, browser, research, or workflow agent Agent Archetypes Agent Eval Environments & Graders → Tool & Action Guardrails
Choosing which metrics to run Eval Selection Decision Tree Metric Cheatsheet
Choosing which guardrails to add Guardrail Selection Decision Tree Guardrails Architecture
Getting ready for launch Implementation Playbook: Launch Readiness Threat Model & OWASP
Debugging a drop in live quality Monitoring, Alerting & Drift Production Data Flywheel
Preparing for a security or RBAC review Access Control & RBAC Tool & Action Guardrails
Benchmarking your team's maturity Maturity Model Implementation Playbook
Comparing open-source and vendor tools Eval & Observability Tools Guardrail Tools

The core mental model in one table

Every eval and guardrail in this repository is defined by six choices:

Choice Your options Where to learn more
1. When it runs • Offline (on datasets before deploy)
• Online (async on live traffic)
• Runtime guardrail (inline on live requests)
The Map
2. Data it uses • SME golden dataset
• Synthetic dataset
• Production-sampled traces
01 · Datasets
3. Scope • End-to-end (question → final answer)
• Component (retriever, reranker, router, tool caller, SQL generator, citation step)
02 · Offline Evals
4. Grading method • Deterministic code
• Statistical/IR math
• Small ML classifier
• LLM-as-a-judge
• Human review
LLM-as-a-Judge
5. Reference data • Reference-based (compares against a known-correct answer)
• Reference-free (grades using only question + context + output)
End-to-End RAG Evals
6. Guardrail action • Blocking (allow, deny, modify, escalate)
• Non-blocking (flag and log)
• Rollout: shadow → flag → block
• Sync vs. Async
Guardrails Architecture

The central rule: A single check (such as "Is every claim supported by retrieved context?") can run as an offline eval in CI, an online monitor on a 1–5% sample of live traffic, and a blocking guardrail before returning high-risk answers. Only the latency budget and failure action change.


Full table of contents

00 · Foundations

Guide What you will learn
01 · Why Evals and Guardrails Why demos fail in production, how evals and guardrails share one check, the error analysis loop (Analyze → Measure → Improve), and how to tell whether a change is real
02 · The Evals & Guardrails Map The five axes that classify every check, the three reliability loops, master lookup tables, and Python code showing one check deployed three ways
03 · Agentic RAG Failure Modes Stage-by-stage failures (query, routing, retrieval, generation, citations, tools, SQL, security, multi-turn memory, long-horizon and multi-agent runs), each with its symptom, root cause, eval, and fix
04 · Glossary Plain-English definitions for ~200 terms used across this repository
05 · Agent Archetypes How to reuse this guide for agents beyond RAG: what carries over, what changes per archetype, and three axes (autonomy, horizon, blast radius)

01 · Datasets

Guide What you will learn
01 · Dataset Strategy Five data sources, JSON row schemas per eval type, coverage tuples and unanswerable slices, and dataset sizing with paired tests and power
02 · SME Golden Datasets Working with domain experts, binary rubrics and key facts, judge-validation sets (≥100 labels, 30–50 FAILs), and reviewer agreement (κ, AC1, prevalence paradox)
03 · Synthetic Datasets Structured generation (dimensions → tuples → scenario → query) for QA, multi-hop, tool, SQL, and adversarial cases, then over-generate and filter
04 · Production Data Flywheel Measurement vs. discovery sampling, inclusion probabilities and re-weighting, judge-error correction, regression suites, and PII-scrubbed, versioned datasets

02 · Offline Evals

Guide What you will learn
01 · End-to-End RAG Evals The RAG triad, answer correctness, context recall, abstention on unanswerable questions, the 2×2 diagnosis matrix, and current RAGAS v0.4 metric names
02 · Retrieval Metrics Recall@k, Precision@k, Hit Rate@k, MRR, MAP, nDCG@k (linear vs. exponential gain), ERR, RBP, span-level labels, and per-stage retrieval evals in Python
03 · Generation Quality & Safety Tone, conciseness, toxicity, bias, PII leakage, harmful advice, over- and under-refusal, and indirect prompt injection (attack success rate, utility under attack)
04 · Agent, Tool & Trajectory Evals Tool selection and argument matching, trajectories, final-state checks, error recovery, pass^k vs. pass@k, and simulated multi-turn users
05 · Text-to-SQL Evals Static syntax, schema, and safety checks, database-enforced read-only controls, execution and test-suite accuracy, efficiency, and schema linking
06 · Instruction & Citation Adherence System prompts as testable contracts, format and JSON schema checks, citation precision/recall, and refusal recall vs. false refusals
07 · LLM-as-a-Judge Binary Pass/Fail rubrics, validating judges against human labels (TPR/TNR ≥ 0.85, κ ≥ 0.60), bias and injection tests, and correcting pass rates (Rogan–Gladen, PPI)
08 · Running Offline Experiments Paired comparisons (McNemar, paired bootstrap), power and sample size, slice gates, ablations, and staged CI gates
09 · Agent Eval Environments & Graders Resettable environments and outcome graders for agent evals, task validity checks, grader hacking, and long-horizon milestones
10 · Decision Model Evals (experimental) Calibration, cost-based thresholds, and escalation paths for models that return typed answers with probabilities
11 · Long-Horizon & Research Agent Evals Claim-level report grading, citation audits, harness changes as experiments, and compaction probes for long-running agents

03 · Online Evals & Observability

Guide What you will learn
01 · Online Evals Deterministic checks on 100% of traffic, sampled LLM judges, sample sizing and judge-error correction, and shadow, canary, and A/B tests (CUPED, sequential tests)
02 · Observability & Tracing One trace per turn, version tags, OpenTelemetry GenAI conventions and OpenInference, PII scrubbing and trace ACLs, span links, and metric cardinality
03 · User Feedback & Implicit Signals Explicit and implicit feedback linked to traces, feedback as a triage signal (not a rate), and staged promotion to dataset labels
04 · Monitoring, Alerting & Drift Sliced KPIs, SLOs and multi-window burn-rate alerts, drift statistics (PSI, KS, two-proportion tests), four drift axes, and an AI incident runbook

04 · Guardrails

Guide What you will learn
01 · Guardrails Architecture Defense-in-depth layers, guardrail actions, latency budgets, fail-open vs. fail-closed rules, and the shadow → flag → block rollout
02 · Input Guardrails Input normalization (invisible Unicode, confusables, encodings), prompt injection and jailbreak detectors and their limits, PII, scope, and over-blocking tests
03 · Retrieval & Context Guardrails Ingestion-time provenance and injection scanning, permission-filtered search, relevance gates, spotlighting, and limiting actions after untrusted content
04 · Output Guardrails Groundedness and citation checks, PII and secret redaction, hidden context exposure (LLM08:2026), schema validation, markdown exfiltration, and streaming
05 · Tool & Action Guardrails Tool tiers, a tool-call gate, approval, budgets, sandboxing, taint tracking, SQL guards, MCP safety, multi-agent and A2A guardrails, and coding or computer-use controls
06 · Access Control & RBAC End-user identity propagation, ACL pre-filters, row-level security that agent SQL cannot switch off, agent workload identity, and RBAC test matrices
07 · Threat Model & OWASP OWASP LLM Top 10 (2026) with a 2025 → 2026 mapping, OWASP Agentic Top 10 (2026), the lethal trifecta and Rule of Two, NIST AI RMF, MITRE ATLAS, and red-teaming

05 · Decision Framework

Guide What you will learn
01 · Eval Selection Decision Tree Five scoping questions, a universal core, and decision trees to pick metrics for your architecture and stage
02 · Guardrail Selection Decision Tree Risk scoring into Tiers 1–3, and which guardrails must block, run synchronously or asynchronously, and fail closed
03 · Metric Cheatsheet Every metric and guardrail check summarized in one reference table
04 · Implementation Playbook A 7-phase rollout plan from day zero to production, with RACI tables and launch checklists
05 · Maturity Model Levels 0 to 4 with a self-assessment scorecard for your team

06 · Tooling Landscape

Guide What you will learn
01 · Eval & Observability Tools One system of record plus swappable metric libraries: RAGAS, DeepEval, TruLens, promptfoo, Arize Phoenix, Langfuse, LangSmith, Braintrust, and more compared
02 · Guardrail Tools Policy engines (OPA, Cedar, OpenFGA), injection classifiers, guard models (Llama Guard, Qwen3Guard), NeMo Guardrails, Presidio, and cloud guardrails compared

07 · References

Curated papers, practitioner essays, security standards, benchmarks, and courses.


The running example

To keep every concept concrete, all guides use the same scenario:

Acme Internal Assistant, an enterprise agent that:

  1. Answers document questions over company policies and wikis using vector + keyword search, reranking, and citations.
  2. Answers data questions by generating SQL against a data warehouse (text-to-SQL).
  3. Takes actions via tools (such as create_ticket, send_email, and run_python). The full list of nine tools and their risk tiers is in Tool & Action Guardrails.
  4. Serves multiple user roles (employee, manager, analyst, support_agent, hr_partner, finance, admin), enforcing strict RBAC on every document, table, and tool call.

The example is RAG-heavy, but most checks apply to any agent. Agent Archetypes shows what changes for coding, browser, deep research, and policy-bound workflow agents.

How these guides are written

  • Quick orientation: Every page starts with a 3–4 bullet TL;DR and ends with Key takeaways and Further reading.
  • Consistent metric cards: Metrics are explained using a standard card: What it measures · Inputs required · How it works · Score range · Common pitfalls · When to use.
  • Calibrate your own thresholds: Sample sizes and score thresholds in this repo are starting rules of thumb. Always calibrate them on your own data.