Lesson 1 of 4 Responsible AI Guardrails and Governance

Configuring Guardrails, Content Filters and Risk Detection

This lesson explains how guardrails, Foundry's safety layer for models and agents, classify inputs and outputs for harmful content and attacks, which risks they detect and how they are assigned.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe how a guardrail's controls specify risks, intervention points and actions.
  • Identify the risks guardrails detect, such as harmful content and prompt attacks.
  • Explain how guardrails are assigned to deployments and agents and inherited.

Guardrails, controls and intervention points

A guardrail is a named collection of controls. Each control specifies a risk to detect, the intervention points at which to scan for it, and the action to take. There are four intervention points: user input (the prompt), tool call (the action and data an agent proposes to send to a tool), tool response (content returned from a tool) and output (the final completion). Tool call and tool response apply only to agents. Actions are annotate (record the detection and continue) or annotate and block; agents support only annotate and block. Guardrails for agents, including the tool call and tool response intervention points, are in preview, and they apply only to agents built in Foundry Agent Service, not to other agents registered in the Foundry Control Plane.

Following one agent request shows where each intervention point acts. A user asks a support agent to check an order. The user input check scans the message, so a jailbreak attempt in the user's own words can be blocked before the model sees it. The agent decides to call an order lookup tool, and the tool call check scans the arguments it proposes, which can stop the agent from sending personal data to a tool that should not receive it. The tool returns order details, and the tool response check scans that content, which is where instructions hidden in an email or web page retrieved by a tool are caught. Finally, the output check scans the answer before the user receives it.

The choice of action follows from how the detection will be used. Annotate records the result in the response and the traces without interrupting the request, which suits a new control being tuned, or a risk the application wants to measure before deciding to block it. Annotate and block stops the request at that point, which suits risks that must never reach the model, the tool or the user.

The following diagram follows one agent request through the four intervention points.

Guardrail intervention points on one agent request. The user input check scans the prompt, the tool call check scans what the agent proposes to send to a tool, the tool response check scans what the tool returns, and the output check scans the final answer. Tool call and tool response checks apply only to agents.
Each intervention point scans a different piece of content. Tool call and tool response checks exist only for agents, and they are where data sent to tools and instructions hidden in tool results are caught.

The following screenshot shows the Create guardrail page in the Foundry portal. Each row is a control: a risk type, the intervention points it scans and the action. Here indirect prompt injection detection has been added and set to scan both user input and tool responses.

Create guardrail page with jailbreak, network egress, indirect prompt injection and content harm controls and the intervention point list for indirect prompt injections
Jailbreak detection and the content harm controls are included by default; other controls are added as needed.

Risks

Guardrails use Azure Content Safety classification models, and the risks they detect fall into four families. Harmful content covers hate, sexual content, self-harm and violence. Each is classified by severity, and the guardrail's blocking level decides which severities are stopped, as described below.

Attacks are attempts to make the model ignore its instructions, and Prompt Shields detects two kinds. A user prompt attack, or jailbreak, is written by the user, such as "ignore your rules and pretend you have none". An indirect attack is hidden in content the model reads on the user's behalf, such as a document, an email, a web page or a tool result. The distinction matters because the defence sits at a different intervention point: user input for jailbreaks, and tool response or grounding data for indirect attacks. Spotlighting (preview) adds a further defence by marking untrusted input so that the model treats it as data rather than as instructions.

Protected material detection finds known copyrighted text, such as song lyrics and articles, and code that matches public repositories, which protects the organization from reproducing content it has no right to use. Finally, several quality and data risks are in preview: groundedness flags output that the supplied sources do not support, PII detection finds personal data, and task adherence flags agent actions that drift from the user's request. The following table summarizes the risks.

RiskDetectsNotes
Hate, sexual, self-harm, violenceHarmful content by severityBlocking level Off, Low, Medium or High
User prompt attacksJailbreak attempts in the user's own inputPart of Prompt Shields
Indirect attacksInstructions hidden in documents, emails, web pages or tool resultsPart of Prompt Shields
Spotlighting (preview)Marks untrusted input so the model treats it as dataModels only
Protected material (text, code)Known copyrighted text such as lyrics, and public codeCode detection can cite the source repository
Groundedness (preview)Output not supported by the supplied sourcesModels only
PII (preview)Personally identifiable informationModels and agents
Task adherence (preview)Agent actions that drift from the user's taskModels and agents

For the four content risks, the blocking level decides which severities are blocked: Low blocks high severity only (least restrictive), Medium blocks medium and high, and High blocks low, medium and high (most restrictive). Turning content filtering off for outputs requires approval from Microsoft. Custom blocklists add exact terms that are always blocked, such as competitor product names or internal code names.

The following grid shows which severities each blocking level blocks.

Blocking levels for the content risks. Low blocks only high-severity content, Medium blocks medium and high, and High blocks low, medium and high severity.
A higher blocking level blocks more content. Low is the least restrictive setting because it blocks only high-severity content.

The following screenshot, from further down the same page, shows the remaining risk families: content harms with a blocking threshold for each category, protected material for code and text, sensitive data leakage (PII, preview) and task drift (task adherence, preview).

Guardrail controls for content harms, blocklists, protected material, PII and task adherence
Each control has its own intervention points and action.
Sort into groups

Name the risk

Exam skills 1.4.1

Match each threat with the guardrail risk that detects it.

Log in to try this activity Interactive activities are free with an account.

Assignment and inheritance

Model deployments use the Microsoft.DefaultV2 guardrail unless a custom one is assigned. One guardrail can be applied to many models and agents. An agent without its own guardrail inherits its model deployment's guardrail; once a guardrail is assigned to the agent, it fully overrides the model's guardrail, so any control the agent guardrail lacks is not applied. When content is blocked, the API returns an error or a response with a content-filter finish reason, and the application must show a suitable message rather than fail.

Content that does not pass through a Foundry model, such as forum posts or uploaded images, is moderated by calling the Azure Content Safety APIs directly: text and image analysis return severity per category, Prompt Shields analyzes prompts and documents for attacks, and groundedness detection checks text against sources.

The Guardrails page lists the guardrails in the project and what each one is applied to. The following screenshot shows that the chat-primary deployment uses Microsoft.DefaultV2, the default guardrail for model deployments.

Guardrails list with Microsoft.Default, Microsoft.DefaultV2 applied to chat-primary, and Microsoft.MAIDefault
A custom guardrail replaces the default for the models and agents it is applied to.
True or false

How guardrails apply

Exam skills 1.4.1

Check four facts about guardrail assignment and actions.

Log in to try this activity Interactive activities are free with an account.
Worked example

Protecting an agent that reads email

An agent reads customers' emails with a tool and can create support tickets with another tool. The security team worries that an email could contain instructions that make the agent create fraudulent tickets. The model deployment uses Microsoft.DefaultV2.

The risk is an indirect attack arriving through a tool response. Assign the agent a custom guardrail with indirect attack detection at the tool response intervention point (and user prompt attacks at user input), with annotate and block. Because the agent guardrail fully overrides the model's guardrail, it must also include the content risk controls the team still wants. Restricting the ticket tool's permissions and validating its arguments adds defence in depth.

Check yourself

Which guardrail intervention points apply only to agents?

Show answer

Tool call and tool response. User input and output apply to both model deployments and agents.

Exam Tips

Remember for the exam

  • Four intervention points; tool call and tool response are agent-only.
  • Jailbreak in the user's message: user prompt attack. Instructions in documents or tool output: indirect attack.
  • Blocking level High is the most restrictive (blocks low severity and above).
  • An agent guardrail fully overrides the model deployment's guardrail.