removing id -> str costly field validator

This commit is contained in:
Sydney Runkle 2025-05-13 19:26:12 -07:00
parent 0da364fbc8
commit 48284ccbb4

View File

@ -4,7 +4,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING, Any, Optional, Union, cast
from pydantic import ConfigDict, Field, field_validator
from pydantic import ConfigDict, Field
from langchain_core.load.serializable import Serializable
from langchain_core.utils import get_bolded_text
@ -52,7 +52,7 @@ class BaseMessage(Serializable):
model implementation.
"""
id: Optional[str] = None
id: Optional[str] = Field(default=None, coerce_numbers_to_str=True)
"""An optional unique identifier for the message. This should ideally be
provided by the provider/model which created the message."""
@ -60,13 +60,6 @@ class BaseMessage(Serializable):
extra="allow",
)
@field_validator("id", mode="before")
def cast_id_to_str(cls, id_value: Any) -> Optional[str]:
"""Coerce the id field to a string."""
if id_value is not None:
return str(id_value)
return id_value
def __init__(
self, content: Union[str, list[Union[str, dict]]], **kwargs: Any
) -> None: