Topological defects in liquid crystals not only affect the optical and rheological properties of the host, but can also act as scaffolds in which to trap nano or micro-sized colloidal objects. The creation of complex defect shapes, however, often involves confining the liquid crystals in curved geometries or adds complex-shaped colloidal objects, which are unsuitable for device applications. Using topologically patterned substrates, here we demonstrate the controlled generation of three-dimensional defect lines with non-trivial shapes and even chirality, in a flat slab of nematic liquid crystal. By using the defect lines as templates and the electric response of the liquid crystals, colloidal superstructures are constructed, which can be reversibly reconfigured at a voltage as low as 1.3 V. Three-dimensional engineering of the defect shapes in liquid crystals is potentially useful in the fabrication of self-healing composites and in stabilizing artificial frustrated phases.