mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-29 10:08:13 +00:00
complete validation
This commit is contained in:
@@ -11,6 +11,7 @@ from typing import (
|
|||||||
Type,
|
Type,
|
||||||
TypeVar,
|
TypeVar,
|
||||||
Union,
|
Union,
|
||||||
|
cast,
|
||||||
)
|
)
|
||||||
|
|
||||||
from pydantic import BaseModel, ValidationError
|
from pydantic import BaseModel, ValidationError
|
||||||
@@ -216,10 +217,18 @@ class Flow(Generic[T], metaclass=FlowMeta):
|
|||||||
if isinstance(self._state, BaseModel):
|
if isinstance(self._state, BaseModel):
|
||||||
# Structured state management
|
# Structured state management
|
||||||
try:
|
try:
|
||||||
# Create a new instance with updated values to ensure validation
|
M = self._state.__class__
|
||||||
self._state = self._state.__class__(
|
|
||||||
**{**self._state.model_dump(), **inputs}
|
# Dynamically create a new model class with 'extra' set to 'forbid'
|
||||||
|
class ModelWithExtraForbid(M):
|
||||||
|
model_config = M.model_config.copy()
|
||||||
|
model_config["extra"] = "forbid"
|
||||||
|
|
||||||
|
# Create a new instance using the combined state and inputs
|
||||||
|
self._state = cast(
|
||||||
|
T, ModelWithExtraForbid(**{**self._state.model_dump(), **inputs})
|
||||||
)
|
)
|
||||||
|
|
||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
raise ValueError(f"Invalid inputs for structured state: {e}") from e
|
raise ValueError(f"Invalid inputs for structured state: {e}") from e
|
||||||
elif isinstance(self._state, dict):
|
elif isinstance(self._state, dict):
|
||||||
|
|||||||
Reference in New Issue
Block a user