Alternatives to Generative Types
Overview
GenerativeType
, which subclasses Pydantic’s BaseModel
,
should support most Object Orientation features required to write effective Generative Functions.
This page lists alternatives that may also be useful.
Dataclasses and BaseModel
If alternatives to Generative Types are required,
classes which use the @dataclass
decorator or subclass Pydantic’s BaseModel
are supported.
These can be used as both inputs and outputs to Generative Functions and as fields of Generative Types.
Custom classes
In some cases it may be necessary to write custom classes for use as fields of Generative Types.
For this to work, these custom classes need to be compatible with Pydantic. This involves adding a method telling Pydantic how to validate the class and how to generate a JSON schema for it, as explained in the Pydantic custom types docs.
Implementing the required methods can be tricky and time-consuming. It’s recommended to stick to supported types (such as BaseModel or dataclass) as much as possible.