union_field
ExceptionGroupError
Bases: MarshmallowUnionError
Collection of possibly multiple exceptions.
Source code in griptape/schemas/union_field.py
MarshmallowUnionError
Union
Bases: Field
Field that accepts any one of multiple fields.
Source: https://github.com/adamboche/python-marshmallow-union Each argument will be tried until one succeeds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fields
|
list[Field]
|
The list of candidate fields to try. |
required |
reverse_serialize_candidates
|
bool
|
Whether to try the candidates in reverse order when serializing. |
False
|
Source code in griptape/schemas/union_field.py
_candidate_fields = fields
instance-attribute
_reverse_serialize_candidates = reverse_serialize_candidates
instance-attribute
__init__(fields, *, reverse_serialize_candidates=False, **kwargs)
Source code in griptape/schemas/union_field.py
_deserialize(value, attr=None, data=None, **kwargs)
Deserialize value
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Any
|
The value to be deserialized. |
required |
attr
|
str | None
|
The attribute/key in |
None
|
data
|
Any
|
The raw input data passed to the |
None
|
kwargs
|
Any
|
Field-specific keyword arguments. |
{}
|
Raises:
Type | Description |
---|---|
ValidationError
|
If an invalid value is passed or if a required value is missing. |
Source code in griptape/schemas/union_field.py
_serialize(value, attr, obj, **kwargs)
Pulls the value for the given key from the object, applies the field's formatting and returns the result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Any
|
The value to be serialized. |
required |
attr
|
str | None
|
The attribute or key to get from the object. |
required |
obj
|
str
|
The object to pull the key from. |
required |
kwargs
|
Any
|
Field-specific keyword arguments. |
{}
|
Raises:
Type | Description |
---|---|
ValidationError
|
In case of formatting problem |