Skip to content

bamltype doesnt impl serialize/deserialize #53

Open

Description

@darinkishore
No description provided.

Activity

  1. darinkishore commented on Feb 12, 2026

    @darinkishore
    CollaboratorAuthor

    Codebase audit

    BamlType trait (bamltype/src/lib.rs:99-105):

    pub trait BamlType: Sized + 'static {
        fn baml_output_format() -> &'static OutputFormatContent;
        fn baml_internal_name() -> &'static str;
        fn baml_type_ir() -> TypeIR;
        fn try_from_baml_value(value: BamlValue) -> Result<Self, BamlConvertError>;
        fn to_baml_value(&self) -> BamlValue;
    }

    BamlSchema requires Facet but not Serialize/Deserialize. The #[BamlType] macro derives Facet only.

    Where serde would be needed:

    • Caching (CacheEntry stores Prediction which is Serialize + Deserialize)
    • Data storage (data storage #55) — persisting call results
    • User code that wants to serialize their #[BamlType] structs to JSON/disk

    Options:

    1. Have #[BamlType] also derive Serialize, Deserialize by default (most user-friendly, slight compile overhead)
    2. Add an opt-in: #[BamlType(serde)] that adds the derives
    3. Leave it to users to derive serde themselves alongside #[BamlType]

    Option 1 seems right for a framework crate — users expect their data types to be serializable. The macro already adds #[derive(Facet)]; adding #[derive(Serialize, Deserialize)] is the same pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions