In this report, an ultrasonication and vacuum assisted headspace solid-phase microextraction procedure followed by gas chromatography-flame ionization detection (UVA-HS-SPME-GC-FID) was proposed for direct extraction of solvent residuals, including benzene, toluene, ethyl benzene, m,p-xylene and o-xylene, in pharmaceutical matrices. A novel robust, reliable and durable nanocomposite solid-phase microextraction (SPME) fiber was prepared by layer-by-layer coating of 3-aminopropyltriethoxysilane-functionalized graphene (APTES) on a stainless-steel wire. Then, the proposed fiber was used for headspace SPME (HS-SPME) and trapping of toluene as a residual solvent in solid penicillin, Ampicillin, and Cefazolin vials followed by gas chromatography-flame ionization detection (GC-FID). UVA-HS-SPME-GC-FID achieves better validation parameters, including limit of detection, limit of quantification, linearity, recovery and repeatability, in comparison with conventional HS-SPME-GC-FID. The UVA-HS-SPME-GC-FID strategy is very effective for quantitative tracing of volatile and semivolatile solvent residuals in various pharmaceutical drugs.