Machine learning tools can be used to efficiently emulate processes in air quality and climate simulations but are not inherently physically consistent or as interpretable as models built on first principles. We introduce a framework to ensure that these data-driven tools adhere to conservation laws as hard constraints by posing fluxes, rather than tendencies, as the learning task. This framework can be embedded into neural networks, where a hidden conservation layer relates system fluxes to local tendencies. We demonstrate the layer’s efficacy in a neural network emulator of smog formation. The conservation layer specifies the graph locality of the chemical mechanism and conserves atoms to machine precision as they flow between molecules. We also present an alternative approach, based on weighted least-squares, that factors in uncertainty and variability of targets to project any nonphysical prediction to the closest prediction that conserves atoms.