code: def title_must_have_value(
      cls: "BaseModel", v: Optional[str], values: Dict[str, Any]
  ) -> str:
      """Function to add as a `pydantic` validator to a field.
  
      This function will be called when the field is being validated, and it will
      receive the value of the field, and the values of the model being validated.
  
      If the field `title` is not empty, then it will be returned as is. Otherwise,
      the value of the field `name` will be capitalized and returned.
      """
      if not v:
          # If `name` doesn't pass the regex validation, then `values` won't have it
          name = values.get("name")
          if name:
              # If `name` has a value, then capitalize it and return it as the `title`
              return name.capitalize()
      return v
  
imports: from typing import TYPE_CHECKING, Any, Dict, Optional
label_desc: Use image node_id 1 for calling a global function with example usage: title_must_have_value(cls, v, values) and returns: v, name