Skip to content

feat: Add support for guardrails - #277

Open
milesapnash wants to merge 1 commit into
mainfrom
feat/guardrails
Open

feat: Add support for guardrails#277
milesapnash wants to merge 1 commit into
mainfrom
feat/guardrails

Conversation

@milesapnash

Copy link
Copy Markdown
Contributor

Summary

Adds a new guardrails resource type to ADK, supporting both platform (toggle-only) and custom (prompt/action-defined) guardrails, synced through agent_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

  • Added PlatformGuardrail and CustomGuardrail resource classes in src/poly/resources/guardrails.py, both stored in agent_settings/guardrails.yaml
  • PlatformGuardrail supports only the enabled toggle against the platform's fixed guardrail catalog (GuardrailName proto enum), with YAML-friendly short names (e.g. jailbreak_defence)
  • CustomGuardrail supports full create/update/delete with name, prompt, action, and enabled fields, plus reference validation against other resource types (global_functions, sms, handoff, attributes, variables, translations)
  • Registered both resource classes via register_resource and exported them from src/poly/resources/__init__.py
  • Added discover_resources/from_projection/to_yaml_dict/from_yaml_dict/validate implementations for both resource types
  • Added guardrails fixture (agent_settings/guardrails.yaml) and updated test_project.json in the test fixture project
  • Added extensive unit tests in src/poly/tests/resources_test.py

Test strategy

  • Added/updated unit tests
  • Manual CLI testing (poly <command>)
  • Tested against a live Agent Studio project
  • N/A (docs, config, or trivial change)

Checklist

  • ruff check . and ruff format --check . pass
  • pytest passes
  • No breaking changes to the poly CLI interface (or migration path documented)
  • Commit messages follow conventional commits

@milesapnash
milesapnash requested review from a team and Ruari-Phipps August 19, 2026 13:14
@linear-code

linear-code Bot commented Aug 19, 2026

Copy link
Copy Markdown

AM-912

DEVP-178

@github-actions

Copy link
Copy Markdown
Contributor

Coverage Report

Base (main) PR Change
75.6% 75.8% +0.2% ✅

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)}"
)

@Ruari-Phipps Ruari-Phipps Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do all of them have to exist? If they can't be deleted/removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants