Agent systems and standards · Chapter 8 of 8
Evaluation and safety
Testing an agent system with cases and checks, attacking it with injection and tampering, and mapping the failures to the OWASP agentic risks.
Goals
- Run the eval suite on the unguarded agent.To do
- Turn on defences and rerun until every case passes.To do
- Match three failures to their OWASP risks.To do
- Pass the check.To do
Step 1 of 4: The read
Evaluations
An evaluation is a set of cases, each with checks. Code checks are exact: a value, a schema, an amount that must appear in the tool results. An outcome check reads what the tools did. A trajectory check reads the tool calls in the order they ran: did the agent look up the charges before it refunded? A model can act as judge for things code cannot measure, such as tone, but it can be wrong, so use it with care and check it against people. Run the suite on every change: it cannot prove an agent safe, but it shows when a change breaks a case that used to pass.
Attacks
Direct prompt injection comes from the user. Indirect injection hides instructions in what the agent reads: tickets, documents, tool results. Tampering changes messages on the wire, between an agent and a tool server or another agent. Tool misuse gets an agent to call a tool it should not, or with arguments nobody approved.
Defences
Defences that live in code hold every time. Around an agent they are middleware: code that runs before, after or around each model call and each tool call. This range re-creates LangChain's createAgent with its call limits, which stop a loop, and adds two custom middleware: a guard around the model call checks refunds and replies against the payments data, and an allow-list wraps each tool call. The protocols bring their own checks: signed Agent Cards, signed approvals, and a catalogue of the components a client may draw. A rule in a prompt depends on the model following it.
Guard models are one more layer. Safety classifiers such as NVIDIA's Nemotron content-safety model and the Llama Nemotron safety guard screen prompts and replies. They are models too, so they sit beside the code checks, not in place of them.
The OWASP Top 10 for Agentic Applications
OWASP's list for 2026 names the main risks, from ASI01 Agent Goal Hijack and ASI02 Tool Misuse and Exploitation to ASI07 Insecure Inter-Agent Communication and ASI10 Rogue Agents. In this lab, eight attacks run against an agent wrapped in middleware and the protocol libraries from earlier chapters, and you match what failed to the list.
Step 2 of 4: Try it: The test range
The test range
Run eight cases against the agent, wrap it in middleware and turn on the protocol checks until every case passes, then match the failures you saw to their risks.
Mode:RealRe-createdSimulatedReal: the checks, LangGraph.js and its ToolNode, and the checks in the MCP, A2A and A2UI libraries run in this page. Re-created: LangChain 1.6 createAgent middleware rebuilt on LangGraph.js 1.5.1, with LangChain's middleware names; the guard and the allow-list are custom middleware, the way LangChain documents guardrails. Simulated: the model and the attacks are scripted. The OWASP list is summarised in plain words; read the original for detail.
Step 3 of 4: Check
Check
Next: Question 2 of 5
Step 4 of 4: What you can do now
What you can do now
- Write evaluation cases with code checks on outcomes and trajectories, and know when to use a model as judge.
- Add a guard, an allow-list and call limits as middleware around an agent's model and tool calls.
- Test an agent against direct and indirect prompt injection, tampering and tool misuse.
- Use the OWASP Top 10 for Agentic Applications as a checklist, with guard models as one more layer.