Skip to content

Commit

Permalink
fix bug in pydantic type casting for union of lists and dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ShreyaR committed Mar 5, 2024
1 parent 2f23a1c commit 201ea56
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion guardrails/classes/output_type.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from typing import Dict, List, TypeVar

OT = TypeVar("OT", str, Dict, List)
OT = TypeVar("OT", str, List, Dict)
4 changes: 4 additions & 0 deletions guardrails/classes/validation_outcome.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Generic, Iterator, Optional, Tuple, Union, cast

from pydantic import Field
from rich.pretty import pretty_repr

from guardrails.classes.history import Call, Iteration
from guardrails.classes.output_type import OT
Expand Down Expand Up @@ -83,3 +84,6 @@ def __iter__(
def __getitem__(self, keys):
"""Get a subset of the ValidationOutcome's fields."""
return iter(getattr(self, k) for k in keys)

def __str__(self) -> str:
return pretty_repr(self)
4 changes: 4 additions & 0 deletions guardrails/utils/reask_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def _gather_reasks_in_list(
valid_output = deepcopy(validated_output)
_gather_reasks_in_dict(validated_output, valid_output)
return reasks, valid_output
elif isinstance(validated_output, List):
valid_output = deepcopy(validated_output)
_gather_reasks_in_list(validated_output, valid_output)
return reasks, valid_output
return reasks, None


Expand Down

0 comments on commit 201ea56

Please sign in to comment.