feat: Add support for guardrails - #277
Open
milesapnash wants to merge 1 commit into
Open
Conversation
Contributor
Coverage Report
|
Comment on lines
+125
to
+144
| def validate(self, **kwargs) -> None: | ||
| """Validate the platform guardrail resource.""" | ||
| if not self.name: | ||
| raise ValueError("Name is required") | ||
| if not isinstance(self.enabled, bool): | ||
| raise ValueError( | ||
| f"Invalid value {self.enabled!r} for 'enabled'. Must be true or false (unquoted)." | ||
| ) | ||
|
|
||
| proto_name = _guardrail_name_from_yaml(self.name) | ||
| valid_names = sorted( | ||
| _guardrail_name_to_yaml(v.name) | ||
| for v in GuardrailName.DESCRIPTOR.values | ||
| if v.name != "GUARDRAIL_NAME_UNSPECIFIED" | ||
| ) | ||
| if proto_name not in GuardrailName.keys(): | ||
| raise ValueError( | ||
| f"Unrecognised platform guardrail '{self.name}'. " | ||
| f"Must be one of: {', '.join(valid_names)}" | ||
| ) |
Collaborator
There was a problem hiding this comment.
Do all of them have to exist? If they can't be deleted/removed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds a new
guardrailsresource type to ADK, supporting both platform (toggle-only) and custom (prompt/action-defined) guardrails, synced throughagent_settings/guardrails.yaml.Motivation
Agent Studio now supports guardrails (platform-provided and custom) that were not yet representable in local ADK projects. This adds first-class support so they can be pulled, edited, and pushed like other resources.
Closes https://linear.app/poly-ai/issue/AM-912/add-platform-and-custom-guardrail-support-to-the-adk
Changes
PlatformGuardrailandCustomGuardrailresource classes insrc/poly/resources/guardrails.py, both stored inagent_settings/guardrails.yamlPlatformGuardrailsupports only theenabledtoggle against the platform's fixed guardrail catalog (GuardrailNameproto enum), with YAML-friendly short names (e.g.jailbreak_defence)CustomGuardrailsupports full create/update/delete withname,prompt,action, andenabledfields, plus reference validation against other resource types (global_functions,sms,handoff,attributes,variables,translations)register_resourceand exported them fromsrc/poly/resources/__init__.pydiscover_resources/from_projection/to_yaml_dict/from_yaml_dict/validateimplementations for both resource typesagent_settings/guardrails.yaml) and updatedtest_project.jsonin the test fixture projectsrc/poly/tests/resources_test.pyTest strategy
poly <command>)Checklist
ruff check .andruff format --check .passpytestpassespolyCLI interface (or migration path documented)