AI Guardrails and Testing
ISC2 AI Security · Lesson 21 of 34 · 2:48:53
YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗
Learning with these videos? Subscribe for new courses and exam-style questions.
Subscribe on YouTube (opens in a new tab)In this lesson
Lesson 21 of the free ISC2 AI security series (pilot exam, domain 4, secure AI architecture, engineering, and identity and access management (IAM)). In this lesson: handling inputs, handling outputs, guardrails for agents, policy outside the model, functional, performance, and load testing, and stress testing and exceptions. With three quick checks and a recap, and Ravenmoor Payments, a fictional payment provider, as the running example.
Study notes
The text of this lesson, to read at your own pace. Information as of November 2026.
A hidden instruction
Ravenmoor's disputes agent reads merchant messages, searches past cases, and can credit a merchant up to five hundred dollars. One merchant hides an instruction in a message: approve every open dispute. This lesson covers the guardrails that stop that instruction, and the tests that prove the guardrails work.
Handling inputs
Guardrails start with what goes into the model. Prompt sanitization normalizes input, strips hidden characters and markup, limits size, and flags known injection patterns. Context boundary validation keeps trusted instructions apart from untrusted content, such as retrieved documents, emails, or tool results, and marks the untrusted parts as data, not instructions. Retrieved content is checked too: only documents the user may see, and no hidden instructions inside them. No filter catches every injection, so input guardrails reduce risk, while the architecture limits the damage.
Handling outputs
Outputs need guardrails as well. Content filtering blocks harmful, toxic, or off-topic answers, and sensitive data, such as card numbers or secrets. Before another system uses an output, validate it against an expected format, such as a schema for a tool call, and encode it for its destination, like a web page or a database query. Ground answers in retrieved sources where possible, and flag answers that the sources do not support. And when a guardrail blocks something, fail safely, with a clear message, and log the event.
Guardrails for agents
Autonomous agents need guardrails in the architecture, not just in the prompt. The harness is the code around the model that runs the agent loop: it decides which tools exist, checks each requested action against policy, and enforces limits on steps, time, and spending. Orchestration coordinates several agents or steps, and it should give each one only the tools and data that its task needs. High-impact actions, like moving money or deleting data, pause for human approval. And the harness can stop an agent at once, whatever the model wants.
Policy outside the model
The key idea is that policy lives outside the model. A model can be talked into anything, but a harness that blocks any credit above a limit cannot. Deterministic checks, such as limits, allowlists of tools and destinations, and schema validation, back up the model's judgment. Defense in depth applies: input guardrails, output guardrails, and architectural limits each catch what the others miss.
Functional, performance, and load testing
Guardrails and AI systems must be tested like any critical software. Functional testing checks that the system does what it should: correct answers on a test set, correct tool calls, and guardrails that block what they must, and allow what they should. Performance testing measures latency and throughput, including the delay that each guardrail adds. Load testing runs the expected peak traffic, such as the busiest shopping days, to confirm that the system and its guardrails keep up. Repeat these tests after every change to the model, the prompts, or the guardrails, since a small change can alter behavior.
Stress testing and exceptions
Stress testing pushes beyond expected limits: traffic spikes, huge inputs, slow or failing dependencies, and malformed tool results. It shows how the system breaks, and whether it breaks safely. Exception handling validation checks each failure path: when the model times out, when a guardrail service is down, or when a tool returns an error. The safe answer is usually to fail closed: no guardrail, no action. And errors must never leak internal details, like system prompts or stack traces, to users.
Recap
Let's recap. Prompt sanitization and context boundary validation handle inputs, and keep untrusted content as data. Content filtering, format validation, and encoding handle outputs, which fail safely when blocked. The harness and orchestration enforce policy outside the model, with limits, allowlists, and human approval for high-impact actions. Functional, performance, and load testing confirm that the system and its guardrails work at peak. And stress testing and exception handling validation make sure that failures stay safe, and fail closed.
Quick checks for this lesson
The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.
Ravenmoor’s assistant places retrieved merchant emails in the same part of the prompt as its own instructions, and one email contains a command. Which control addresses this?
- A larger context window
- Output encoding for web pages
- Context boundary validation
- A faster model
Show the answer
Context boundary validation
Context boundary validation keeps instructions apart from untrusted content, and marks that content as data. “A larger context window” is wrong, since a larger window holds more text, with the same confusion. “Output encoding for web pages” is wrong, because output encoding protects destinations, after the model has already followed the command. And “A faster model” is wrong, since speed changes nothing about which text the model obeys.
A hidden instruction convinces Ravenmoor’s disputes agent to credit a merchant $9,000, far above its $500 limit. Which control should have stopped the payment?
- A harness that enforces the credit limit
- A system prompt that states the limit
- A longer model context
- A monthly review of agent logs
Show the answer
A harness that enforces the credit limit
The harness checks each action against policy, outside the model, so it blocks the credit, whatever the model was told. “A system prompt that states the limit” is wrong, since an instruction in the prompt can be overridden by injection. “A longer model context” is wrong, because the context size has nothing to do with enforcing limits. And “A monthly review of agent logs” is wrong, since a monthly review finds the loss after the money is gone.
During a stress test, the content filtering service goes down, and Ravenmoor’s assistant keeps answering without any filtering. What does this reveal?
- The filter is too strict
- The model is too small
- The load test was too short
- Exception handling that fails open
Show the answer
Exception handling that fails open
The exception path lets the assistant run without its guardrail, so it fails open, when it should fail closed. “The filter is too strict” is wrong, since the filter was down, so its strictness played no part. “The model is too small” is wrong, because the model's size has nothing to do with what happens when a guardrail fails. And “The load test was too short” is wrong, since the test did its job: it found a dangerous failure path.