from uuid import uuid4 try: from typing import Annotated except ImportError: from typing_extensions import Annotated from pydantic import BaseModel, Field class Foo(BaseModel): id: Annotated[str, Field(default_factory=lambda: uuid4().hex)] name: Annotated[str, Field(max_length=256)] = 'Bar'