Make sure inputs adhere to state type.

This commit is contained in:
Brandon Hancock
2024-11-01 16:14:36 -04:00
parent 9a41206a0d
commit 40248aadec

View File

@@ -216,7 +216,10 @@ class Flow(Generic[T], metaclass=FlowMeta):
if isinstance(self._state, BaseModel): if isinstance(self._state, BaseModel):
# Structured state management # Structured state management
try: try:
self._state = self._state.model_copy(update=inputs) # Create a new instance with updated values to ensure validation
self._state = self._state.__class__(
**{**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):