docstr: A FastAPI validator for parsing metadata dictionary
  
  Parameters
  ----------
  metadata:
      The metadata dictionary
  
  Returns
  -------
      A flatten version of metadata dictionary
docstr_tok: ["A","FastAPI","validator","for","parsing","metadata","dictionary","Parameters","--","--","--","--","--","metadata",":","The","metadata","dictionary","Returns","--","--","--","-","A","flatten","version","of","metadata","dictionary"]
code: def parse_metadata(cls, metadata: Dict[str, Any]):
      """
      A FastAPI validator for parsing metadata dictionary
  
      Parameters
      ----------
      metadata:
          The metadata dictionary
  
      Returns
      -------
          A flatten version of metadata dictionary
  
      """
      if metadata:
          metadata_protected = {}
          metadata_parsed = {}
  
          for k, v in metadata.items():
              if k.startswith(PROTECTED_METADATA_FIELD_PREFIX):
                  metadata_protected[k] = v
              else:
                  metadata_parsed[k] = limit_value_length(
                      v, settings.metadata_field_length
                  )
  
          metadata_parsed = {
              **flatten_dict(metadata_parsed, drop_empty=True),
              **metadata_protected,
          }
  
          if metadata != metadata_parsed:
              message = (
                  "Some metadata values exceed the max length. Those values will be"
                  f" truncated by keeping only the last {settings.metadata_field_length} characters. "
                  + _messages.ARGILLA_METADATA_FIELD_WARNING_MESSAGE
              )
              warnings.warn(message, UserWarning)
              metadata = metadata_parsed
      return metadata
  
imports: import uuid
  import warnings
  from datetime import datetime
  from typing import Any, Dict, Generic, List, Optional, TypeVar, Union
  from argilla import _messages
  from argilla.server.commons.models import PredictionStatus, TaskStatus, TaskType
  from argilla.server.constants import JS_MAX_SAFE_INTEGER, PROTECTED_METADATA_FIELD_PREFIX
  from argilla.server.daos.backend.search.model import BaseRecordsQuery, SortConfig
  from argilla.server.helpers import flatten_dict
  from argilla.server.pydantic_v1 import BaseModel, Field, conint, constr, root_validator, validator
  from argilla.server.pydantic_v1.generics import GenericModel
  from argilla.server.settings import settings
  from argilla.utils import limit_value_length
label_desc: Use image node_id 5 for calling the BaseRecordInDB obj's underlying member method code with example usage: obj.parse_metadata(cls, metadata) and returns: metadata