Skip to content

model_artifact

ModelArtifact

Bases: GenericArtifact[BaseModel]

Stores Pydantic models as Artifacts.

Required since Pydantic models require a custom serialization method.

Attributes:

Name Type Description
value BaseModel

The pydantic model to store.

Source code in griptape/artifacts/model_artifact.py
@define
class ModelArtifact(GenericArtifact[BaseModel]):
    """Stores Pydantic models as Artifacts.

    Required since Pydantic models require a custom serialization method.

    Attributes:
        value: The pydantic model to store.
    """

    # We must explicitly define the type rather than rely on the parent T since
    # generic type information is lost at runtime.
    value: BaseModel = field(metadata={"serializable": True})

    def to_text(self) -> str:
        return self.value.model_dump_json()

value = field(metadata={'serializable': True}) class-attribute instance-attribute

to_text()

Source code in griptape/artifacts/model_artifact.py
def to_text(self) -> str:
    return self.value.model_dump_json()