|
| 1 | +"""Guardrails models for UiPath Platform.""" |
| 2 | + |
| 3 | +from enum import Enum |
| 4 | +from typing import Annotated, Literal |
| 5 | + |
| 6 | +from pydantic import BaseModel, ConfigDict, Field |
| 7 | +from uipath.core.guardrails import BaseGuardrail |
| 8 | + |
| 9 | + |
| 10 | +class EnumListParameterValue(BaseModel): |
| 11 | + """Enum list parameter value.""" |
| 12 | + |
| 13 | + parameter_type: Literal["enum-list"] = Field(alias="$parameterType") |
| 14 | + id: str |
| 15 | + value: list[str] |
| 16 | + |
| 17 | + model_config = ConfigDict(populate_by_name=True, extra="allow") |
| 18 | + |
| 19 | + |
| 20 | +class MapEnumParameterValue(BaseModel): |
| 21 | + """Map enum parameter value.""" |
| 22 | + |
| 23 | + parameter_type: Literal["map-enum"] = Field(alias="$parameterType") |
| 24 | + id: str |
| 25 | + value: dict[str, float] |
| 26 | + |
| 27 | + model_config = ConfigDict(populate_by_name=True, extra="allow") |
| 28 | + |
| 29 | + |
| 30 | +class NumberParameterValue(BaseModel): |
| 31 | + """Number parameter value.""" |
| 32 | + |
| 33 | + parameter_type: Literal["number"] = Field(alias="$parameterType") |
| 34 | + id: str |
| 35 | + value: float |
| 36 | + |
| 37 | + model_config = ConfigDict(populate_by_name=True, extra="allow") |
| 38 | + |
| 39 | + |
| 40 | +class EnumParameterValue(BaseModel): |
| 41 | + """Single-select enum parameter value.""" |
| 42 | + |
| 43 | + parameter_type: Literal["enum"] = Field(alias="$parameterType") |
| 44 | + id: str |
| 45 | + value: str |
| 46 | + |
| 47 | + model_config = ConfigDict(populate_by_name=True, extra="allow") |
| 48 | + |
| 49 | + |
| 50 | +class TextParameterValue(BaseModel): |
| 51 | + """Free-text parameter value.""" |
| 52 | + |
| 53 | + parameter_type: Literal["text"] = Field(alias="$parameterType") |
| 54 | + id: str |
| 55 | + value: str |
| 56 | + |
| 57 | + model_config = ConfigDict(populate_by_name=True, extra="allow") |
| 58 | + |
| 59 | + |
| 60 | +class TextListParameterValue(BaseModel): |
| 61 | + """List-of-text parameter value.""" |
| 62 | + |
| 63 | + parameter_type: Literal["text-list"] = Field(alias="$parameterType") |
| 64 | + id: str |
| 65 | + value: list[str] |
| 66 | + |
| 67 | + model_config = ConfigDict(populate_by_name=True, extra="allow") |
| 68 | + |
| 69 | + |
| 70 | +ValidatorParameter = Annotated[ |
| 71 | + EnumListParameterValue |
| 72 | + | MapEnumParameterValue |
| 73 | + | NumberParameterValue |
| 74 | + | EnumParameterValue |
| 75 | + | TextParameterValue |
| 76 | + | TextListParameterValue, |
| 77 | + Field(discriminator="parameter_type"), |
| 78 | +] |
| 79 | + |
| 80 | + |
| 81 | +#: Sentinel ``validator_type`` for Bring Your Own Guardrail (BYOG) guardrails; the |
| 82 | +#: connector-backed configuration is referenced by ``byo_validator_name`` instead. |
| 83 | +BYO_VALIDATOR_TYPE = "byo" |
| 84 | + |
| 85 | + |
| 86 | +class BuiltInValidatorGuardrail(BaseGuardrail): |
| 87 | + """Built-in validator guardrail model.""" |
| 88 | + |
| 89 | + guardrail_type: Literal["builtInValidator"] = Field(alias="$guardrailType") |
| 90 | + validator_type: str = Field(alias="validatorType") |
| 91 | + validator_parameters: list[ValidatorParameter] = Field( |
| 92 | + default_factory=list, alias="validatorParameters" |
| 93 | + ) |
| 94 | + byo_validator_name: str | None = Field(default=None, alias="byoValidatorName") |
| 95 | + |
| 96 | + model_config = ConfigDict(populate_by_name=True, extra="allow") |
| 97 | + |
| 98 | + |
| 99 | +class GuardrailType(str, Enum): |
| 100 | + """Guardrail type enumeration.""" |
| 101 | + |
| 102 | + BUILT_IN_VALIDATOR = "builtInValidator" |
| 103 | + CUSTOM = "custom" |
0 commit comments