The Vilsmeier formylation involves the reaction of heterocycles rich in electron density with dimethylformamide in the presence of phosphorus oxytrichloride.
Mechanism:
Stage 1. Formation of the Vilsmeier electrophile
Stage 2. Nucleophilic attack of pyrrole on the Vilsmeier electrophile
Stage 3. Recovery of aromaticity
Stage 4. Formation of the immonium salt