The polarization of the Mg ii h and k resonance lines is the result of the joint action of scattering processes and the magnetic field–induced Hanle, Zeeman, and magneto-optical effects, thus holding significant potential for the diagnostic of the magnetic field in the solar chromosphere. The Chromospheric LAyer Spectro-Polarimeter sounding-rocket experiment, carried out in 2019, successfully measured at each position along the 196″ spectrograph slit the wavelength variation of the four Stokes parameters in the spectral region of this doublet around 280 nm, both in an active-region plage and in a quiet region close to the limb. We consider some of these CLASP2 Stokes profiles and apply to them the recently developed HanleRT Tenerife Inversion Code, which assumes a one-dimensional model atmosphere for each spatial pixel under consideration (i.e., it neglects the effects of horizontal radiative transfer). We find that the nonmagnetic causes of symmetry breaking, due to the horizontal inhomogeneities and the gradients of the horizontal components of the macroscopic velocity in the solar atmosphere, have a significant impact on the linear polarization profiles. By introducing such nonmagnetic causes of symmetry breaking as parameters in our inversion code, we can successfully fit the Stokes profiles and provide an estimation of the magnetic field vector. For example, in the quiet region pixels, where no circular polarization signal is detected, we find that the magnetic field strength in the upper chromosphere varies between 1 and 20 G.