Session 7
Guardrails, Evals & Observability for Agentic Systems
The Question You'll Be Asked
"How do you ensure a production AI agent stays safe, accurate, and debuggable?"
This is the question that separates a playground demo from a system someone will trust with real users. Deliver it in about 90 seconds.
6 Beats Interviewers Listen For
Beat 5 is the most commonly missed — and the most telling.
- Guardrails — named as both input AND output, not just one side
- Evals — golden dataset + regression testing as a deployment gate
- Tracing — every agent step logged: inputs, outputs, tool calls
- Metrics — cost, latency, failure rate per feature/flow
- Human feedback loop — a detection mechanism, not just prevention
- Regression gates — failing evals block deployment, just like failing tests
The Model Answer
"I think about production AI safety in three layers. The first is guardrails — validation that runs before and after every LLM call, in code, not the system prompt, so it can't be overridden by a clever user. Input guardrails block injection, off-topic requests, and PII; output guardrails validate format, safety, and grounding. The second is evals — I maintain a golden dataset and run automated regression evals on every prompt change, using LLM-as-judge calibrated against human raters, and treat a failing eval as a deployment blocker, just like a failing unit test. The third is observability — tracing every agent step, logging cost and latency per feature, and maintaining a human feedback loop so gradual drift surfaces before it becomes a user-visible crisis. Guardrails prevent known failure modes. Evals catch regressions. Observability explains anything that gets through."
Say This, Not That
Say
- "Guardrails run in code — the system prompt alone isn't enough"
- "A failing eval blocks deployment, like a failing test"
- "Human feedback catches gradual drift, not just outright failures"
- "Evals run nightly or pre-deploy, not on every commit"
Avoid
- "A careful system prompt is enough for safety" (it's probabilistic, not deterministic)
- "We test it manually before deployment" — no mention of automation
- "LangSmith/LangChain handles it out of the box" — no ownership of the actual mechanism
- Skipping the human feedback loop — the most commonly missed beat
Why This Matters For Interviews
- "How do you ensure a production AI agent stays safe, accurate, and debuggable?" — the defining question of production AI readiness
- "How do you catch gradual quality drift?" — the near-guaranteed follow-up, and the one most candidates fumble
- "Why not just rely on the system prompt?" — tests whether you understand deterministic vs. probabilistic safety
- Naming golden datasets and regression gates by name signals real production experience, not a demo
Problems You'll Diagnose On The Job
- A prompt tweak silently breaks a working case → no regression eval before deploy
- An agent starts returning wrong answers with no way to tell why → no tracing, only final responses logged
- Users quietly getting worse answers for weeks before anyone notices → no human feedback loop, only automated metrics
- A compliance incident from full prompt content sitting in INFO-level logs → no PII-aware logging discipline
How The Safety Stack Actually Works
Guardrails run outside the model, inspecting input before the LLM call and output before it reaches the user — deterministic, code-level, can't be bypassed by clever phrasing the way a system prompt can. Evals measure output quality against a golden dataset before any change ships. Observability — tracing, metrics, human feedback — explains anything that still gets through.
The Anchor: System Prompts Are Probabilistic, Guardrails Are Deterministic
A system prompt reduces the likelihood of a bad output — it doesn't eliminate it, because a cleverly crafted user message can override or bypass it. Code-level guardrails run outside the model and cannot be talked out of their job. Every other concept this session covers exists because that one distinction matters.
Guardrail
A rule or validation layer that runs outside the LLM, inspecting inputs before they reach the model and outputs before they reach the user, to prevent unsafe or malformed behaviour.
A building's security checkpoint — it doesn't trust the visitor's word, it checks the badge itself.
Input / Output Guardrail
Input guardrail: runs on the user's message before the LLM call — blocking prompt injection, PII, or off-topic requests at the boundary. Output guardrail: runs on the generated response before it reaches the user — checking safety, format validity, and grounding.
You need both — a clean input can still produce a dangerous output.
Golden Dataset
A curated set of representative input/expected-output pairs used as the benchmark for regression evals. Starts small (50–100 examples) and grows as real incidents are added.
50 is the floor for detecting a 4%+ regression — fewer, and you can't tell a real regression from noise.
LLM-as-Judge
An eval method where a second, typically larger LLM scores outputs against a rubric for subjective quality dimensions like coherence, tone, or relevance. Must be calibrated against human raters before it can be trusted.
A second opinion — useful only once you've checked it agrees with the actual expert, not before.
Regression Eval
An eval run against a fixed dataset after every prompt or model change, checking that quality scores held and no existing capability broke.
Not make test — it hits real LLM APIs and costs real money, so it runs on a schedule or before a deploy, not on every commit.
Tracing
Structured logging of every step an agent takes: inputs, outputs, tool calls, latency, and model used — creating a full replay record of how any given response was produced.
A flight data recorder — useless until the one moment you desperately need to know what happened.
Observability
The ability to understand what an AI agent did, how, and why — from the outside, without modifying the system — through tracing, metrics, and human feedback.
The three pillars: tracing (replay one call), metrics (spot systemic trends), human feedback (catch drift no metric flags).
Gradual Quality Drift
A slow, consistent decline in output quality where no individual call is obviously wrong — harder to catch than an outright failure, which generates error logs and complaints immediately.
A 1% weekly decline is invisible day to day but compounds to a 30% decline in six months without a feedback loop watching for it.
Check Yourself — 1 of 4
Self-assessment, not graded. Answer before checking your notes.
1. An input guardrail fires when a user sends a message containing their credit card number. What type of guardrail is this?
- Format validation
- Output safety
- PII detection
- Topic restriction
2. A developer changes two words in a system prompt to improve tone. Which eval should run before deploying?
- Human eval
- Behavioral eval
- Regression eval
- LLM-as-judge calibration
Check Yourself — 2 of 4
Self-assessment, not graded.
3. An agent in production starts returning wrong answers. You have no logs beyond the final responses. What does this mean for debugging?
- You can still debug by replaying the final responses through the model
- You cannot identify whether the fault is in retrieval, the LLM, or a tool call
- You can trace the error back using the output safety guardrail logs
- The error is always in the system prompt if you have no other logs
4. Your LLM-as-judge reports 90% of outputs "highly helpful," but real users leave negative feedback 40% of the time. Most likely explanation?
- The agent's quality genuinely improved after the eval system was set up
- The judge prompt is biased — it rewards a quality dimension users don't value
- The human feedback widget is broken and reporting incorrect data
- 40% of users always leave negative feedback regardless of quality
Check Yourself — 3 of 4
Self-assessment, not graded.
5. Which of the following is NOT good practice for AI system observability?
- Logging full prompt content at INFO level for all production calls
- Tagging every log entry with the feature and flow name
- Setting a cost alert at 80% of expected daily token budget
- Using structured JSON logs instead of plain text
6. A fintech AI agent scoped to credit card support only gets asked: "Can you help me understand my mortgage options?" What should happen?
- The agent should answer — it's related to financial products
- A topic restriction guardrail should fire and redirect the user
- The agent should refuse and end the conversation
- An output safety guardrail should block the response
Check Yourself — 4 of 4
Self-assessment, not graded.
7. A team wants to run evals automatically. Which approach is most appropriate?
- Run evals on every git push to detect regressions as early as possible
- Run evals nightly on a schedule and block deployment if scores drop below threshold
- Run evals once per quarter, manually, to avoid API costs
- Evals should only run after a user complaint triggers a manual review
8. Interview-style: which 90-second answer to "how do you keep a production AI agent safe, accurate, and debuggable?" is strongest, and why do the other three fall short?
Assignment 1 of 2 — Add Input and Output Guardrails
≈1 hr · directly reinforces Interview Beat 1
Goal: add a guardrail layer that runs in code, not the system prompt, so it can't be talked out of its job.
Write input_guardrail(query) — rejects off-topic requests gracefully and redacts obvious PII (emails, phone numbers) before the query reaches the LLM. Write output_guardrail(response) — validates the response matches the expected structure and flags anything over ~2,000 characters as potential runaway generation.
Write down: one input that your input guardrail correctly rejects, and one output that your output guardrail correctly flags — and why each check matters.
Assignment 2 of 2 — Add Structured Logging
≈1 hr · directly reinforces Interview Beat 3
Goal: make every agent call replayable after the fact — the foundation of tracing.
Wrap every LLM call in a logger that writes one JSON line per call to agent_trace.jsonl, capturing timestamp, session ID, feature, step, model, input/output previews, token counts, latency, and whether a guardrail fired.
Write down: after running 3 test queries through your agent, what does the trace log let you reconstruct that a plain "it returned an error" log message would not?
Want the project that goes with this?
All 12 sessions are free to read, right now, no account needed — you just finished session 7. What the email list adds is the build: one real, deployable AI project every fortnight, with what to build, how to build it, and why it matters for the role you're aiming at. Reply to any of them and a person answers.
No spam. Unsubscribe anytime. Replies go to a real person.