-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Lorenze/adding guardrails #3711
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
- Added a new `guardrails` field to the Task class to allow for multiple guardrail functions or string descriptions for output validation. - Implemented a model validator to ensure guardrails are processed correctly, supporting both callable functions and string descriptions. - Updated the task execution flow to invoke guardrails sequentially, handling validation and retry logic. - Added comprehensive tests for various guardrail scenarios, including sequential processing, validation failures, and mixed return types. This update improves the flexibility and robustness of task output validation, ensuring better control over task execution outcomes.
- Updated the type annotation for the `guardrails` field in the Task class from `list` to `Sequence` to enhance type safety and compatibility with various sequence types. - This change improves type checking and aligns with best practices for handling callable functions and string descriptions in guardrail validation. This update contributes to the overall robustness and maintainability of the Task class.
- Updated the Task class to ensure that guardrails can only be used when an agent is provided, improving error handling and validation. - Introduced a smart task factory function to automatically assign a mock agent when guardrails are present, maintaining backward compatibility. - Updated tests to utilize the new smart task factory, ensuring proper functionality with and without guardrails. This update enhances the robustness of task execution and guardrail integration, ensuring better control over task validation outcomes.
if self.guardrails is not None and ( | ||
not isinstance(self.guardrails, (list, tuple)) or len(self.guardrails) > 0 | ||
): | ||
if self.agent is None: |
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.
I think the agent check is too early maybe, only string-based guardrails need an agent, right?
@model_validator(mode="after") | ||
def ensure_guardrails_is_list_of_callables(self) -> "Task": | ||
guardrails = [] | ||
if self.guardrails is not None and ( |
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.
did you want to check for empty lists here?
covered by #3728 |
No description provided.