-
Notifications
You must be signed in to change notification settings - Fork 18
feat: Add support for guardrails #277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
milesapnash
wants to merge
10
commits into
main
Choose a base branch
from
feat/guardrails
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
18a2555
feat: Add support for guardrails
milesapnash 63b9304
Merge branch 'main' into feat/guardrails
milesapnash ff10de2
docs: add guardrails.md
milesapnash bfee235
Merge branch 'main' into feat/guardrails
milesapnash 92c9f88
docs: update guardrail docs
milesapnash 7861493
fix: enforce all platform guardrails exist
milesapnash 5b378a9
fix: resolve resources correctly
milesapnash cfa1535
fix: prevent validate() from accepting name: unspecified as a valid p…
milesapnash f1982ac
fix: raise ValueError for non-string guardrail names
milesapnash b4aef0a
refactor: compute catalog/resource discovery at top of file
milesapnash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| --- | ||
| title: Guardrails | ||
| description: Configure platform and custom guardrails that constrain agent behavior during a conversation. | ||
| --- | ||
|
|
||
| # Guardrails | ||
|
|
||
| <p class="lead"> | ||
| Guardrails are runtime checks that constrain what the agent can say or do, catching problems a prompt or rule alone can't reliably prevent. | ||
| </p> | ||
|
|
||
| There are two kinds: a fixed catalog of **platform guardrails** you can only toggle on or off, and **custom guardrails** you define yourself with a trigger condition and an action. | ||
|
|
||
| ## Location | ||
|
|
||
| Both kinds of guardrail live in a single optional file: | ||
|
|
||
| ~~~text | ||
| agent_settings/ | ||
| └── guardrails.yaml # Optional | ||
| ~~~ | ||
|
|
||
| ## What guardrails control | ||
|
|
||
| <div class="grid cards" markdown> | ||
|
|
||
| - **Platform guardrails** | ||
|
|
||
| --- | ||
|
|
||
| A fixed set of platform-provided checks. Only the `enabled` toggle can be changed. | ||
|
|
||
| - **Custom guardrails** | ||
|
|
||
| --- | ||
|
|
||
| Your own rules: a prompt describing when the guardrail should trigger, and an action describing what happens when it does. | ||
|
|
||
| </div> | ||
|
|
||
| ## Platform guardrails | ||
|
|
||
| !!! note "Fixed catalog — enable or disable only" | ||
| The catalog of platform guardrails is fixed by the platform. You can enable or disable each one, but you cannot create a new platform guardrail or delete an existing one via the ADK. | ||
|
|
||
| ### The catalog | ||
|
|
||
| | Name | Description | | ||
| |---|---| | ||
| | `ai_identity` | Has the agent disclose that it's an AI when asked. | | ||
| | `emergency_escalation` | Detects emergencies and escalates instead of continuing the conversation normally. | | ||
| | `hallucination_control` | Reduces factually unsupported or made-up responses. | | ||
| | `jailbreak_defence` | Detects and blocks attempts to override the agent's instructions or persona. | | ||
| | `tool_call_integrity` | Checks that the agent's function/tool calls are well-formed and intended. | | ||
|
|
||
| ### Fields | ||
|
|
||
| | Field | Description | | ||
| |---|---| | ||
| | `name` | One of the fixed catalog names above. | | ||
| | `enabled` | `true` or `false`. Default: `true`. | | ||
|
|
||
| ### Example | ||
|
|
||
| ~~~yaml | ||
| platform_guardrails: | ||
| - name: jailbreak_defence | ||
| enabled: true | ||
| - name: hallucination_control | ||
| enabled: false | ||
| ~~~ | ||
|
|
||
| ## Custom guardrails | ||
|
|
||
| Custom guardrails live under an optional `custom_guardrails` list in the same file. Unlike platform guardrails, they can be created, updated, and deleted via the ADK. | ||
|
|
||
| ### Fields | ||
|
|
||
| | Field | Description | | ||
| |---|---| | ||
| | `name` | Display name for the guardrail. | | ||
| | `prompt` | Describes the condition that triggers the guardrail. Free text — references are not evaluated here. | | ||
| | `action` | Describes what the agent should do when the guardrail triggers, for example `warn`, or an instruction that calls a function, handoff, or SMS template. | | ||
| | `enabled` | `true` or `false`. Default: `true`. | | ||
|
|
||
| ### Supported references in `action` | ||
|
|
||
| `action` is the only field scanned for references — a reference written in `prompt` is treated as plain text. | ||
|
|
||
| It accepts every prefix in the [resource references table](../../development/resource-architecture.md#resource-references) except two: flow transition functions (`{{ft:...}}`) and entities (`{{entity:...}}`) fail validation in a guardrail action. | ||
|
|
||
| ### Example | ||
|
|
||
| ~~~yaml | ||
| custom_guardrails: | ||
| - name: No medical advice | ||
| enabled: true | ||
| action: warn | ||
| prompt: Never give medical advice. Offer to transfer the caller to a human instead. | ||
| ~~~ | ||
|
|
||
| ## Validation | ||
|
|
||
| Validation rejects a `guardrails.yaml` that doesn't satisfy these rules: | ||
|
|
||
| - Every platform guardrail's `name` must be one of the fixed catalog names; anything else is rejected with the list of valid names. | ||
| - Every platform guardrail in the fixed catalog must be present in the file — none can be missing, though any can be `enabled: false`. | ||
| - Every platform and custom guardrail's `enabled` must be a boolean (`true`/`false`, unquoted). | ||
| - A custom guardrail's `name`, `prompt`, and `action` are all required. | ||
| - Any `{{prefix:name}}` reference in a custom guardrail's `action` must use one of the supported prefixes above, and must resolve to a resource that actually exists. | ||
|
|
||
| ## Best practices | ||
|
|
||
| - Keep `prompt` focused on the trigger condition and `action` focused on the response; don't fold both into one field. | ||
| - Disable a platform or custom guardrail with `enabled: false` instead of deleting it, so it's easy to re-enable later. | ||
|
milesapnash marked this conversation as resolved.
|
||
|
|
||
| ## Related pages | ||
|
|
||
| <div class="grid cards" markdown> | ||
|
|
||
| - **Safety filters** | ||
|
|
||
| --- | ||
|
|
||
| Content filtering on user input and agent output, configured per channel. | ||
| [Open safety filters](./safety_filters.md) | ||
|
|
||
| - **Agent settings** | ||
|
|
||
| --- | ||
|
|
||
| Personality, role, and rules — the other resources that shape agent behavior. | ||
| [Open agent settings](./agent_settings.md) | ||
|
|
||
| - **Functions** | ||
|
|
||
| --- | ||
|
|
||
| Global functions that a custom guardrail's action can call. | ||
| [Open functions](./functions.md) | ||
|
|
||
| </div> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.