-
Notifications
You must be signed in to change notification settings - Fork 16
Add GuardrailAgent prompt param support #32
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for a prompt parameter to GuardrailAgent to make it a 1:1 drop-in replacement for the Agents SDK. Previously, GuardrailAgent required an instructions parameter, but the Agents SDK allows using a prompt parameter instead.
- Added
_resolve_agent_instructionshelper function to derive instructions from either explicit instructions or prompt parameters - Modified
GuardrailAgent.__new__to accept optionalinstructionsand handlepromptparameter viaagent_kwargs - Added validation to ensure either
instructionsorpromptis provided during initialization
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/guardrails/agents.py | Added prompt parameter support and instruction resolution logic to GuardrailAgent |
| tests/unit/test_agents.py | Added test cases for prompt parameter functionality and updated Agent stub |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| prompt_arg: Any | None = agent_kwargs.get("prompt") | ||
| resolved_instructions = _resolve_agent_instructions(instructions, prompt_arg) | ||
|
|
||
| if resolved_instructions is None and prompt_arg is None: |
Copilot
AI
Oct 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation logic is incorrect. The condition should check if resolved_instructions is None, not both resolved_instructions is None and prompt_arg is None. If a prompt is provided but doesn't yield valid instructions (e.g., an object without the expected attributes), the agent should still fail to initialize.
| if resolved_instructions is None and prompt_arg is None: | |
| if resolved_instructions is None: |
| guardrails_pkg = types.ModuleType("guardrails") | ||
| guardrails_pkg.__path__ = [str(Path(__file__).resolve().parents[2] / "src" / "guardrails")] | ||
| sys.modules.setdefault("guardrails", guardrails_pkg) |
Copilot
AI
Oct 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module setup code should be moved to a test fixture or conftest.py rather than being placed at module level. Module-level sys.modules manipulation can cause issues with test isolation and make debugging more difficult.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This reverts commit 632e4a0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest closing in favor of PR 34
|
Closing in favor of #34 |
Via bug report:
One minor thing, it seems like your Guardrail Agent isn't a 1:1 drop in for the Agents SDK, using a remote prompt gives me an error.