-
-
Notifications
You must be signed in to change notification settings - Fork 901
Expand file tree
/
Copy pathguardrail_result.py
More file actions
43 lines (34 loc) · 1.33 KB
/
guardrail_result.py
File metadata and controls
43 lines (34 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
Guardrail result classes for PraisonAI Agents.
This module provides the result types for guardrail validation,
following the same pattern as CrewAI for consistency.
"""
from typing import Any, Tuple, Union
from pydantic import BaseModel, Field
from ..output.models import TaskOutput
class GuardrailResult(BaseModel):
"""Result of a guardrail validation."""
success: bool = Field(description="Whether the guardrail check passed")
result: Union[str, TaskOutput, None] = Field(description="The result if modified, or None if unchanged")
error: str = Field(default="", description="Error message if validation failed")
@classmethod
def from_tuple(cls, result: Tuple[bool, Any]) -> "GuardrailResult":
"""Create a GuardrailResult from a tuple returned by a guardrail function.
Args:
result: Tuple of (success, result_or_error)
Returns:
GuardrailResult: The structured result
"""
success, data = result
if success:
return cls(
success=True,
result=data,
error=""
)
else:
return cls(
success=False,
result=None,
error=str(data) if data else "Guardrail validation failed"
)