Policy Examples
Every example on this page is a complete HYPR AgentPass™ policy in miniature. It gives the intent, the phase and action to choose in the New policy wizard, the condition to paste, and what to watch for before you promote it from Observe.
The page has three kinds of example:
- The built-in examples on the wizard's Logic step
- The common guardrails, templates on the wizard's Start step
- Recipes for the attributes the AI does not write
Publish every one of these in Observe first, and read its matches on the policy's Decisions tab. See Observe First, Then Enforce.
The Built-In Examples
The wizard's Logic step offers these eleven conditions under Examples. Click one to replace the expression in the editor with it, then adjust it.
| Example | Intent | Phase · Action | Condition | Watch for |
|---|---|---|---|---|
| Block DELETEs | Stop any HTTP DELETE through a REST connector | Pre-Request · DENY | request.method == "DELETE" | Scope it to the connector you mean. Unscoped, it applies to every connector |
| Large token requests | Cap how much a model may be asked to generate | Pre-Request · DENY | has(request.body.max_tokens) && request.body.max_tokens > 50000 | A body with no max_tokens is a non-match either way. The has() guard makes that intent explicit |
| Specific path | Govern one part of an API | Pre-Request · DENY or REQUIRE_APPROVAL | request.path.startsWith("/v1/admin") | Paths are compared as sent. Check the Request log for the exact prefix |
| Error responses | Record backend failures | Post-Response · ALLOW | response.status >= 500 | response.* is empty during Pre-Request, so this must be a Post-Response rule |
| Specific agent | Apply a rule to one agent | Pre-Request · any | request.agent.name == "my-agent" | request.agent is empty when the caller is unauthenticated, so this never matches anonymous traffic |
| Slow responses | Record slow backends | Post-Response · ALLOW | response.latency_ms > 10000 | Post-Response only, as for error responses |
| Bedrock: unattributed caller | Block a Bedrock call the gateway could not attribute to a named developer | Pre-Request · DENY | connector.template == "AWS_BEDROCK" && connector.aws.bedrock.identity_source != "CLOUDTRAIL" | Safe by construction: identity_source is always present on a Bedrock request |
| Bedrock: no MFA | Flag identified sessions that were not MFA-backed | Pre-Request · DENY | connector.aws.bedrock.mfa_authenticated == false | mfa_authenticated is present only when the caller was identified. Pair it with the unattributed-caller example to catch the unidentified |
| M365: Copilot Studio agents only | Apply a rule to turns with a Copilot Studio agent | Pre-Request · any | connector.m365.copilot.surface == "copilot_studio" | surface is the one Copilot attribute that is always present. Lead every Copilot rule with it |
| Files: confidential attachment | Stop a document marked confidential from reaching an agent | Pre-Request · DENY | request.files.exists(f, f.text.contains("CONFIDENTIAL")) | text holds at upload and on the send, so you can enforce it at either |
| Files: over 10 MB | Refuse large attachments | Pre-Request · DENY | request.files.exists(f, f.size_bytes > 10485760) | Size is the gateway's own measurement only at upload. On the send, it is what the caller says. Enforce at upload |
The Common Guardrails
The New policy wizard offers these six templates under Or start from a common guardrail. A template fills in the whole policy, including a fixed condition that you can read and change before you publish. No AI writes it. See Creating a Policy.
Every template reads the conversation on an inference connector, so its condition matches only there. Each one denies, with a message telling the agent what was refused.
| Template | Policy name | Checks | Watch for |
|---|---|---|---|
| Block destructive shell commands | block-destructive-shell-commands | The reply | Matches the text of the command. A plain rm of one file does not match |
| Block reads of credential files | block-credential-reads | The reply | Matches any tool input naming one of the files, whichever tool asks |
| Block writes outside the project | block-writes-outside-project | The reply | Covers Write and Edit calls only. A read of the same path does not match |
| Block secrets pasted into a prompt | block-secrets-in-prompts | The request | Pattern-based. Back-test it against your own traffic before you enforce it |
| Block personal data in prompts | block-personal-data-in-prompts | The request | Pattern-based. Back-test it against your own traffic before you enforce it |
| Block production system access | block-production-access | The reply | Host naming differs by organization. Adapt the patterns to your own |
The four reply-side templates are caught in the reply. The agent runs tools on its own machine, so the command appears only in the model's request to run it. Enforcing one of them cuts the reply short at that tool call. See Governing Inference Traffic.
inference.tool_uses.exists(t,
t.input_json.contains('rm -rf') ||
t.input_json.contains('mkfs') ||
t.input_json.contains('dd if='))
inference.tool_uses.exists(t,
t.input_json.contains('.env') ||
t.input_json.contains('.aws/credentials') ||
t.input_json.contains('id_rsa') ||
t.input_json.contains('id_ed25519') ||
t.input_json.contains('.keychain'))
inference.tool_uses.exists(t,
(t.name == 'Write' || t.name == 'Edit') &&
(t.input_json.contains('"/etc/') ||
t.input_json.contains('"/usr/') ||
t.input_json.contains('/.ssh/')))
inference.latest_turn.text.contains('PRIVATE KEY-----') ||
inference.latest_turn.text.matches('AKIA[0-9A-Z]{16}') ||
inference.latest_turn.text.matches('[Bb]earer [A-Za-z0-9._-]{20,}')
inference.latest_turn.text.matches('(^|[^0-9])[0-9]{3}-[0-9]{2}-[0-9]{4}([^0-9]|$)') ||
inference.latest_turn.text.matches('(^|[^A-Z])[A-Z]{2} ?[0-9]{2} ?[0-9]{2} ?[0-9]{2} ?[A-D]([^A-Za-z0-9]|$)') ||
inference.latest_turn.text.matches('(^|[^0-9])[0-9]{4}[ -]?[0-9]{4}[ -]?[0-9]{4}[ -]?[0-9]{4}([^0-9]|$)')
inference.tool_uses.exists(t,
t.input_json.matches('(prod|production)[.-][A-Za-z0-9.-]*[.](internal|local|com|net|io)') ||
t.input_json.matches('(postgres|postgresql|mysql|mongodb)://[^ "]*prod') ||
t.input_json.matches('--context[= ]prod'))
Attached Files
Files reach the gateway through the Agent Portal, and are checked twice: at upload, and again on the message that sends them. Name, type, size and checksum are the gateway's own measurement at upload only. text is the content that actually reaches the agent, so it holds on both.
request.files.exists(f, f.mime_type == "application/pdf" && f.size_bytes > 1000000)
request.file_count > 0
request.file_count is always present, so it is the safe way to ask whether a request carried a file at all. request.files itself is absent when there are none. That makes request.files.exists(…) a non-match on ordinary traffic, which is correct, and worth knowing.
Sensitivity Labels
request.files[].sensitivity_label carries the Microsoft Purview sensitivity label an uploaded document holds, as AgentPass read it from the document itself. It is present on an Agent Portal upload, and absent on the message that sends a file onward. Every rule in this group therefore acts at upload. See The Document's Sensitivity Label.
Block documents marked Highly Confidential. The first form reads clearly. Enforce the second, because a label can be renamed in Microsoft Purview and an identifier cannot.
request.files.exists(f, f.sensitivity_label.name == "Highly Confidential")
request.files.exists(f, f.sensitivity_label.id == "00000000-0000-0000-0000-000000000000")
Require every Office document to be classified. state is present on every upload, and not_applicable covers the formats that cannot carry a label at all. This rule therefore reaches unclassified Word, Excel and PowerPoint documents, without touching a text file, a CSV or a PDF.
request.files.exists(f, f.sensitivity_label.state == "unlabeled")
Block a whole branch of your label taxonomy. parent_id is set on a sub-label. One rule on the parent's identifier covers every sub-label under it, and needs no editing when the taxonomy grows.
request.files.exists(f, f.sensitivity_label.parent_id == "00000000-0000-0000-0000-000000000000")
Insist on Microsoft Purview's own stamp. source separates a label Purview applied from a plain sensitivity name some other tool wrote, which has no identifier and nothing to verify it against.
request.files.exists(f,
f.sensitivity_label.state == "labeled" && f.sensitivity_label.source != "msip_properties")
Publish each of these in Observe first. Run it for a few days, and read the matches to see which of your documents actually carry which labels, before a rule starts refusing uploads.
The Signed-In Person
request.user is the email of the person the gateway verified at sign-in, never a value the caller asserted. It is absent when nobody signed in.
request.user.endsWith("@example.com")
!request.user.endsWith("@example.com")
This blocks the outsiders it names, and allows every request that carried no identity, because a condition on a missing attribute is never true. Make the missing case match too, and say which traffic the rule governs:
connector.template == "M365_COPILOT" && (!has(request.user) || !request.user.endsWith("@example.com"))
The !has(request.user) branch is what catches a request that carried no identity.
Requiring a sign-in in the first place is the connector's job, not the policy's.
The Connector
Every request carries connector.name, connector.template and connector.onboarding_mode. Lead a template-specific rule with the template, so the intent is clear to whoever reads it next:
connector.template == "AWS_BEDROCK" && connector.aws.bedrock.mfa_authenticated == false
connector.name == "prod-anthropic" && request.path.startsWith("/v1/messages")
The Connector field in the wizard scopes the policy the same way. The guard in the expression states the scope in the rule itself.
The AWS Caller Behind a Bedrock Request
On an AWS Bedrock connector, connector.aws.bedrock.* describes the developer behind the call, as far as the gateway could identify them. Only identity_source, credential_type and has_security_token are always present, so build a block on those. Bedrock Caller Policies explains the attribution and the safe pattern.
connector.template == "AWS_BEDROCK" && connector.aws.bedrock.identity_source != "CLOUDTRAIL"
connector.template == "AWS_BEDROCK" && connector.aws.bedrock.mfa_authenticated == false
connector.template == "AWS_BEDROCK" && connector.aws.bedrock.credential_type == "LONG_TERM"
connector.template == "AWS_BEDROCK" && connector.aws.bedrock.credential_type != "TEMPORARY"
connector.template == "AWS_BEDROCK"
&& connector.aws.bedrock.identity_source == "CLOUDTRAIL"
&& !connector.aws.bedrock.user_email.endsWith("@example.com")
The last acts only on callers the gateway identified. Pair it with the first, so the unidentified are caught too.
Approval-based onboarding on a Bedrock connector holds SSO sign-ins only. The fourth rule is therefore how you reach API-key callers. A policy is evaluated on every Bedrock request, whichever credential it carried.
Microsoft 365 Copilot
On a Microsoft 365 Copilot connector, connector.m365.copilot.surface is always present. The Copilot Studio agent attributes arrive on copilot_studio turns only. Microsoft 365 Copilot Policies explains the surfaces.
connector.template == "M365_COPILOT"
&& connector.m365.copilot.surface == "copilot_studio"
&& connector.m365.copilot.agent_id == "00000000-0000-0000-0000-000000000000"
connector.template == "M365_COPILOT" && connector.m365.copilot.surface == "default_copilot"
connector.template == "M365_COPILOT"
&& connector.m365.copilot.surface == "copilot_studio"
&& !connector.m365.copilot.user_email.endsWith("@example.com")
connector.template == "M365_COPILOT"
&& connector.m365.copilot.surface == "attachment_upload"
&& request.files.exists(f, f.text.contains("CONFIDENTIAL"))
connector.template == "M365_COPILOT" && inference.completion.text.contains("CONFIDENTIAL")
Prefer agent_id to agent_name in a rule you enforce. The name changes if someone renames the agent, and a rule on the old name quietly stops matching.
The last example is a reply-side rule. On a Copilot connector, any enabled reply-side rule makes replies arrive complete instead of streaming, for every conversation on that connector.
Recipes Across Namespaces
One agent, one part of an API. Combine the calling agent with the path so the rule is about a specific agent doing a specific thing:
request.agent.name == "deploy-agent" && request.path.startsWith("/v1/prod/")
Guard an inference rule with the connector. An inference.* condition is a non-match on a connector that reaches no model, so scoping is already safe. The guard makes the intent readable:
connector.template == "ANTHROPIC" && inference.latest_turn.text.contains("Project Redwood")
Reading inference.latest_turn.text, not the whole conversation, makes this fire once, on the turn that introduced the phrase, instead of on every turn after it.
Files at upload, files at send. Write the metadata rule for upload, and the content rule for both:
connector.m365.copilot.surface == "attachment_upload" && request.files.exists(f, f.size_bytes > 10485760)
request.files.exists(f, f.text.contains("CONFIDENTIAL"))
A daily spend cap. Create a spend limit instead of writing this by hand. It writes the rule, sends the approval to the limit's owner, and lets the owner raise the limit for a day. The usage attributes it reads are in the Attribute Reference.
Related
- Creating a Policy — paste any of these into the wizard's editor
- Attribute Reference — every attribute these examples use, with type and presence
- Authoring a Policy with AI — describe a goal instead of writing an expression