def EntityKind(key):
  """Given entity primary key as Reference Proto, returns entity kind.

  Args:
    key: primary key of entity in ReferenceProto form.

  Returns:
    Kind of entity in string format. Returns '' if
    kind cannot be determined in some unexpected scenario.
  """
  if key.path().element_list():
    return key.path().element_list()[-1].type()
  else:
    return ''