- Notifications
You must be signed in to change notification settings - Fork17
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
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 aprompt parameter toGuardrailAgent to make it a 1:1 drop-in replacement for the Agents SDK. Previously,GuardrailAgent required aninstructions parameter, but the Agents SDK allows using aprompt 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) | ||
| ifresolved_instructionsisNoneandprompt_argisNone: |
CopilotAIOct 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 ifresolved_instructions is None, not bothresolved_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.
| ifresolved_instructionsisNoneandprompt_argisNone: | |
| ifresolved_instructionsisNone: |
| guardrails_pkg=types.ModuleType("guardrails") | ||
| guardrails_pkg.__path__= [str(Path(__file__).resolve().parents[2]/"src"/"guardrails")] | ||
| sys.modules.setdefault("guardrails",guardrails_pkg) |
CopilotAIOct 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 commit632e4a0.
steven10a left a comment
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 ofPR 34
gabor-openai commentedOct 30, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.