Skip to content

Conversation

lorenzejay
Copy link
Collaborator

No description provided.

- 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:
Copy link
Contributor

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 (
Copy link
Contributor

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?

@lorenzejay lorenzejay closed this Oct 19, 2025
@lorenzejay
Copy link
Collaborator Author

covered by #3728

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