We introduce a method for shaping the spectral response of nonlinear light sources by tailoring the quasi-phase matching. Our algorithm relies on engineering the poling to accurately trace a generated target signal field amplitude to determine the desired nonlinearity profile. The proposed poling algorithm results in a poling pattern that is more robust to manufacture, as all domain inversions are of equal width. The poling pattern is verified using a nonlinear beam propagation method simulation. This approach is applied to achieve Gaussian-shaped phase matching along a potassium titanyl phosphate (KTP) crystal in order to generate pure heralded single photons of spectral purity ∼0.996 - this is highly desirable for heralded single photon quantum optics.