The comprehensive study reported herein provides compelling evidence that anion templates are the main driving force in the formation of two novel nanoscale lanthanide hydroxide clusters, {Gd38(ClO4)6} (1) and {Gd48Cl2(NO3)} (2), characterized by single-crystal X-ray crystallography, infrared spectroscopy, and magnetic measurements. {Gd38(ClO4)6}, encapsulating six ClO4(-) ions, features a cage core composed of twelve vertex-sharing {Gd4} tetrahedrons and one Gd⋅⋅⋅Gd pillar. When Cl(-) and NO3(-) were incorporated in the reaction instead of ClO4(-), {Gd48Cl2(NO3)} is obtained with a barrel shape constituted by twelve vertex-sharing {Gd4} tetrahedrons and six {Gd5} pyramids. What is more, the cage-like {Gd38} can be dynamically converted into the barrel-shaped {Gd48} upon Cl(-) and NO3(-) stimulus. To our knowledge, it is the first time that the linear M-O-M' fashion and the unique μ8-ClO4(-) mode have been crystallized in pure lanthanide complex, and complex 2 represents the largest gadolinium cluster. Both of the complexes display large magnetocaloric effect in units of J kg(-1) K(-1) and mJ cm(-3) K(-1) on account of the weak antiferromagnetic exchange, the high N(Gd)/M(W) ratio (magnetic density), and the relatively compact crystal lattice (mass density).