From 2ac2bd1b55f4b12876702c2d89a9b00bb7deec60 Mon Sep 17 00:00:00 2001 From: cthomas Date: Thu, 1 May 2025 11:03:34 -0700 Subject: [PATCH] fix: openai illegal char in name check (#1971) --- letta/schemas/message.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/letta/schemas/message.py b/letta/schemas/message.py index 2c273bb6..e12fcb0d 100644 --- a/letta/schemas/message.py +++ b/letta/schemas/message.py @@ -2,6 +2,7 @@ from __future__ import annotations import copy import json +import re import uuid import warnings from collections import OrderedDict @@ -700,9 +701,12 @@ class Message(BaseMessage): else: raise ValueError(self.role) - # Optional field, do not include if null + # Optional field, do not include if null or invalid if self.name is not None: - openai_message["name"] = self.name + if bool(re.match(r"^[^\s<|\\/>]+$", self.name)): + warnings.warn(f"Using OpenAI with invalid 'name' field (name={self.name} role={self.role}).") + else: + openai_message["name"] = self.name if parse_content_parts: for content in self.content: