Context: Ultraviolet (UV) emission-line spectra are used to spectroscopically confirm high-z galaxies and increasingly also to determine their physical properties. Aims: To interpret the observed UV spectra of distant galaxies in terms of the dominant radiation field and the physical condition of the interstellar medium. Methods: We construct a large grid of photoionization models and derive new spectral UV line diagnostics using equivalent widths (EWs) of CIII]1909, CIV1549 and the line ratios of CIII], CIV, and HeII1640 recombination lines. We apply these diagnostics to a sample of 450 CIII]-emitting galaxies at z=2-4 previously identified in the VIMOS Ultra Deep Survey. Results: We show that the average star-forming galaxy (EW(CIII])~2A) is well described by stellar photoionization from single and binary stars. The inferred metallicity and ionization parameter is typically Z=0.3-0.5Zsun and logU=-2.7 to -3, in agreement with earlier works at similar redshifts. The models also indicate an average age of 50-200Myr since the beginning of the current star-formation, and an ionizing photon production rate, xi_ion, of log(xi_ion/[Hz/erg])~25.3-25.4. Among the sources with EW(CIII])=10-20A, ~30% are likely dominated by AGNs. Their derived metallicity is low, Z=0.02-0.2Zsun, and the ionization parameter higher (logU=-1.7). To explain the average UV observations of the strongest but rarest CIII] emitters (EW(CIII])>20A), we find that stellar photoionization is clearly insufficient. A radiation field consisting of a mix of a young stellar population (log(xi_ion/[Hz/erg])~25.7) plus an AGN component is required. Furthermore an enhanced C/O abundance ratio is needed for metallicities Z=0.1-0.2Zsun and logU=-1.7 to -1.5. Conclusions: The UV diagnostics we propose should serve as an important basis for the interpretation of observations of high-redshift galaxies. [abridged]