code: def _serialize_input_data(input_data, content_type):
      # build-docker command is available in mlflow-skinny (which doesn't contain pandas)
      # so we shouldn't import pandas at the top level
      import pandas as pd
  
      valid_input_types = {
          _CONTENT_TYPE_CSV: (str, list, dict, pd.DataFrame),
          _CONTENT_TYPE_JSON: _get_pyfunc_supported_input_types(),
      }.get(content_type)
  
      if not isinstance(input_data, valid_input_types):
          raise MlflowException.invalid_parameter_value(
              f"Input data must be one of {valid_input_types} when content type is '{content_type}', "
              f"but got {type(input_data)}."
          )
  
      # If the input is already string, check if the input string can be deserialized correctly
      if isinstance(input_data, str):
          _validate_string(input_data, content_type)
          return input_data
  
      try:
          if content_type == _CONTENT_TYPE_CSV:
              # We should not set header=False here because the scoring server expects the
              # first row to be the header
              return pd.DataFrame(input_data).to_csv(index=False)
          else:
              return _serialize_to_json(input_data)
      except Exception as e:
          raise MlflowException.invalid_parameter_value(
              message=f"Input data could not be serialized to {content_type}."
          ) from e
  
file_path: mlflow/mlflow/models/python_api.py
imports: import json
  import logging
  import os
  from datetime import datetime
  from io import StringIO
  from typing import ForwardRef, List, Optional, get_args, get_origin
  from mlflow.exceptions import MlflowException
  from mlflow.models.flavor_backend_registry import get_flavor_backend
  from mlflow.utils import env_manager
  from mlflow.utils.file_utils import TempDir
  from mlflow.utils.proto_json_utils import dump_input_data
label_desc: Use image node_id 4 for calling a global function with example usage: _serialize_input_data(input_data, content_type) and returns: input_data, pd, _serialize_to_json