From eaaca141f70a22b6686611c1ac845771d1326905 Mon Sep 17 00:00:00 2001 From: Kian Jones <11655409+kianjones9@users.noreply.github.com> Date: Tue, 27 Jan 2026 23:37:56 -0800 Subject: [PATCH] feat: add ID format validation to identity schemas (#9153) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add ID format validation to identity schemas Add ID format validation to IdentityCreate, IdentityUpsert, and IdentityUpdate schemas using existing validator types from letta.validators. Changes: - agent_ids: Optional[List[str]] → Optional[List[AgentId]] - block_ids: Optional[List[str]] → Optional[List[BlockId]] This ensures malformed IDs are rejected with 422 validation errors instead of causing 500 database errors. 🤖 Generated with [Letta Code](https://letta.com) Co-Authored-By: Letta * chore: regenerate API spec and SDK --------- Co-authored-by: Letta --- fern/openapi.json | 42 +++++++++++++++++++++++++++++++++------ letta/schemas/identity.py | 13 ++++++------ 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/fern/openapi.json b/fern/openapi.json index 43ec694b..9eaed96c 100644 --- a/fern/openapi.json +++ b/fern/openapi.json @@ -34392,7 +34392,12 @@ "anyOf": [ { "items": { - "type": "string" + "type": "string", + "maxLength": 42, + "minLength": 42, + "pattern": "^agent-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$", + "description": "The ID of the agent in the format 'agent-'", + "examples": ["agent-123e4567-e89b-42d3-8456-426614174000"] }, "type": "array" }, @@ -34408,7 +34413,12 @@ "anyOf": [ { "items": { - "type": "string" + "type": "string", + "maxLength": 42, + "minLength": 42, + "pattern": "^block-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$", + "description": "The ID of the block in the format 'block-'", + "examples": ["block-123e4567-e89b-42d3-8456-426614174000"] }, "type": "array" }, @@ -34534,7 +34544,12 @@ "anyOf": [ { "items": { - "type": "string" + "type": "string", + "maxLength": 42, + "minLength": 42, + "pattern": "^agent-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$", + "description": "The ID of the agent in the format 'agent-'", + "examples": ["agent-123e4567-e89b-42d3-8456-426614174000"] }, "type": "array" }, @@ -34550,7 +34565,12 @@ "anyOf": [ { "items": { - "type": "string" + "type": "string", + "maxLength": 42, + "minLength": 42, + "pattern": "^block-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$", + "description": "The ID of the block in the format 'block-'", + "examples": ["block-123e4567-e89b-42d3-8456-426614174000"] }, "type": "array" }, @@ -34614,7 +34634,12 @@ "anyOf": [ { "items": { - "type": "string" + "type": "string", + "maxLength": 42, + "minLength": 42, + "pattern": "^agent-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$", + "description": "The ID of the agent in the format 'agent-'", + "examples": ["agent-123e4567-e89b-42d3-8456-426614174000"] }, "type": "array" }, @@ -34630,7 +34655,12 @@ "anyOf": [ { "items": { - "type": "string" + "type": "string", + "maxLength": 42, + "minLength": 42, + "pattern": "^block-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$", + "description": "The ID of the block in the format 'block-'", + "examples": ["block-123e4567-e89b-42d3-8456-426614174000"] }, "type": "array" }, diff --git a/letta/schemas/identity.py b/letta/schemas/identity.py index bb4f429d..c5602be4 100644 --- a/letta/schemas/identity.py +++ b/letta/schemas/identity.py @@ -5,6 +5,7 @@ from pydantic import Field from letta.schemas.enums import PrimitiveType from letta.schemas.letta_base import LettaBase +from letta.validators import AgentId, BlockId class IdentityType(str, Enum): @@ -57,8 +58,8 @@ class IdentityCreate(LettaBase): name: str = Field(..., description="The name of the identity.") identity_type: IdentityType = Field(..., description="The type of the identity.") project_id: Optional[str] = Field(None, description="The project id of the identity, if applicable.") - agent_ids: Optional[List[str]] = Field(None, description="The agent ids that are associated with the identity.", deprecated=True) - block_ids: Optional[List[str]] = Field(None, description="The IDs of the blocks associated with the identity.", deprecated=True) + agent_ids: Optional[List[AgentId]] = Field(None, description="The agent ids that are associated with the identity.", deprecated=True) + block_ids: Optional[List[BlockId]] = Field(None, description="The IDs of the blocks associated with the identity.", deprecated=True) properties: Optional[List[IdentityProperty]] = Field(None, description="List of properties associated with the identity.") @@ -67,8 +68,8 @@ class IdentityUpsert(LettaBase): name: str = Field(..., description="The name of the identity.") identity_type: IdentityType = Field(..., description="The type of the identity.") project_id: Optional[str] = Field(None, description="The project id of the identity, if applicable.") - agent_ids: Optional[List[str]] = Field(None, description="The agent ids that are associated with the identity.", deprecated=True) - block_ids: Optional[List[str]] = Field(None, description="The IDs of the blocks associated with the identity.", deprecated=True) + agent_ids: Optional[List[AgentId]] = Field(None, description="The agent ids that are associated with the identity.", deprecated=True) + block_ids: Optional[List[BlockId]] = Field(None, description="The IDs of the blocks associated with the identity.", deprecated=True) properties: Optional[List[IdentityProperty]] = Field(None, description="List of properties associated with the identity.") @@ -76,8 +77,8 @@ class IdentityUpdate(LettaBase): identifier_key: Optional[str] = Field(None, description="External, user-generated identifier key of the identity.") name: Optional[str] = Field(None, description="The name of the identity.") identity_type: Optional[IdentityType] = Field(None, description="The type of the identity.") - agent_ids: Optional[List[str]] = Field(None, description="The agent ids that are associated with the identity.", deprecated=True) - block_ids: Optional[List[str]] = Field(None, description="The IDs of the blocks associated with the identity.", deprecated=True) + agent_ids: Optional[List[AgentId]] = Field(None, description="The agent ids that are associated with the identity.", deprecated=True) + block_ids: Optional[List[BlockId]] = Field(None, description="The IDs of the blocks associated with the identity.", deprecated=True) properties: Optional[List[IdentityProperty]] = Field(None, description="List of properties associated with the identity.")