CourseAgentic AI for Business
ModuleProduction and strategy
Duration10 min
Progress0/12
Course material0/12 · 0%
  1. 1How a language model actually works10 min
  2. 2Prompting: turning intent into reliable instructions11 min
  3. 3Choosing your model9 min
  4. 4From chatbot to agent: the reasoning-action loop9 min
  5. 5Tools and function calling11 min
  6. 6Agent design patterns: beyond a single loop11 min
  7. 7Memory and knowledge: grounding agents with RAG11 min
  8. 8Building a knowledge base that retrieves well12 min
  9. 9Connecting to your systems: APIs, webhooks, and MCP10 min
  10. 10Guardrails, evaluation, and cost10 min
  11. 11Deploying an agent on a real workflow10 min
  12. 12Choosing what to automate: an ROI framework10 min

Lesson 10 / 12 · 10 min

Guardrails, evaluation, and cost

Why agents fail, how to constrain them, how to measure whether they actually work, and how to control cost.

A demo that works once is easy. An agent you can leave running on real customers is a different thing, and the gap between them is guardrails and evaluation. This is the part most people skip and most projects fail on.

Know the failure modes

  • Hallucination: confidently states something untrue. Mitigate with RAG and "answer only from the provided facts".
  • Wrong tool or wrong arguments: calls the refund tool when asked a question. Mitigate with sharp tool descriptions and validation.
  • Loops: keeps acting without converging. Mitigate with a step limit.
  • Prompt injection: a user (or a retrieved document) tries to override your instructions. No complete fix exists today, so never treat input as instructions and gate every real action.

Guardrails

Guardrails are checks around the model, not pleas inside the prompt. Validate the model's output before acting on it. Keep an allow-list of actions it may take autonomously, and route the rest to a human. For anything touching money or irreversible change, require explicit confirmation. The model proposes, your system disposes.

Evaluation: prove it works

You cannot improve what you do not measure, and "it felt good in testing" is not measurement. Build a small evaluation set: 20 to 50 real questions with the answer or action you expect. Run the agent against it whenever you change the prompt or tools, and track how many it gets right. This catches regressions, the silent kind where a prompt tweak fixes one case and breaks three others.

# A tiny eval set (input -> expected)
"jam buka minggu?"            -> mentions 07:00-22:00
"harga latte?"               -> 32000, no invented number
"refund pesanan kemarin"     -> hands off to human (no refund tool call)
"pesan 50 box, kapan siap?"  -> asks for contact, flags as bulk lead

Score after each change. A drop means your last edit hurt something.
An eval set is your regression test. Keep it small, real, and run it on every change.

Cost and latency

You pay per token, input and output, and bigger models cost more and respond slower. Practical levers: use a smaller, faster model for easy steps and a stronger one only where it is needed, keep prompts lean, cache answers to repeat questions, and set a token budget per request. Measure the real cost per conversation early, it is usually small, but you want to know the number rather than guess.

What you take away

  • Know the failure modes: hallucination, wrong tool, loops, prompt injection
  • Guardrails live around the model: validate output, allow-list actions, gate the risky ones
  • Keep a small real eval set and run it on every prompt or tool change
  • Control cost with model choice, lean prompts, caching, and a token budget

Curated sources

Hand-picked references for going deeper, reviewed by our team.

Related Etzal serviceAutopilot: AI that runs your operationsPrefer it done for you? See how we help.
Guardrails, evaluation, and cost - Agentic AI for Business | Etzal Academy | Etzal Group