Skip to content

Allow Span.log metadata to serialize Pydantic models #435

@barrettpyke

Description

Description

Currently when calling Span.log the metadata property must be a dictionary. The input property does not have this restriction and instead goes through _to_bt_safe (here) which dumps the model.

It would be nice if the same flow was applied to metadata.

Reproduction

Run the following script:

from pydantic import BaseModel
import braintrust
class M(BaseModel):
    foo: str = "bar"
logger = braintrust.init_logger(project="repro", set_current=False)
with logger.start_span(name="x") as span:
    span.log(input=M(), metadata=M())   # input ok, metadata raises

Expected

It should accept the Pydantic model in the metadata property.

Observed

It throws ValueError: metadata must be a dictionary.

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions