Context. The chemical composition of warm gas giant exoplanet atmospheres (with Teq < 1000 K) is not well known due to the lack of observational constraints. Aims. HAT-P-12 b is a warm, sub-Saturn-mass transiting exoplanet that is ideal for transmission spectroscopy. We aim to characterise its atmosphere and probe the presence of carbonaceous species using near-infrared observations. Methods. One transit of HAT-P-12 b was observed in spectroscopy with JWST NIRSpec in the 2.87─5.10 µm range with a resolving power of ~1000. The JWST data are combined with archival observations from HST WFC3 covering the 1.1─1.7 µm range. The data were analysed using two data reduction pipelines and two atmospheric retrieval tools. Atmospheric simulations using chemical forward models were performed to interpret the spectra. Results. CO2, CO, and H2O are detected at 12.2, 4.1, and 6.0 σ confidence, respectively. Their volume mixing ratios are consistent with an atmosphere of ~10× solar metallicity and production of CO2 by photochemistry. CH4 is not detected and seems to be lacking, which could be due to a high intrinsic temperature with strong vertical mixing or other phenomena. SO2 is also not detected and its production seems limited by low upper atmosphere temperatures (~500 K at P ≲ 10−3 bar derived from one-dimensional retrievals), insufficient to produce it in detectable quantities (≳ 800 K required according to photochemical models). H2S is marginally detected using one data analysis method, but not by the other. Retrievals indicate the presence of clouds between 2 and 11 mbar using one data analysis method, and between 5 and 269 mbar using the other. The derived C/O ratio is below unity, but is not well constrained. Conclusions. This study points towards an atmosphere for HAT-P-12 b that could be enriched in carbon and oxygen with respect to its host star, a possibly cold upper atmosphere that may explain the non-detection of SO2, and a CH4 depletion that is yet to be fully understood. When including the production of CO2 via photochemistry, an atmospheric metallicity that is close to Saturn’s can explain the observations. Metallicities inferred for other gas giant exoplanets based on their CO2 mixing ratios may need to account for its photochemical production pathways. This may impact studies on mass-metallicity trends and links between exoplanet atmospheres, interiors, and formation history.

