It is not known when Du Yan was born, but it is known that he was from Sui Dynasty's capital commandery Jingzhao. His grandfather Du Ye was a provincial governor for Sui's predecessor stateNorthern Zhou, and his father Du Zheng was a commandery governor for Northern Zhou. In his youth, Du Yan had a good reputation for being talented in rhetoric, and he and a friend from the same commandery, Wei Fusi, conversed between themselves and concluded that Emperor Wen of Sui favored people who had been hermits. They therefore went into Mount Taibai, to try to gain reputations as hermits in order to benefit themselves later on in their careers. When Emperor Wen heard this, however, he became angry at them, and he exiled them to the south of the Yangtze River. Later, probably after a general pardon, Du Yan was able to return to Chang'an. Gao Xiaoji, an official of the capital province Yong Province submitted a recommendation for him, and he was made a low level imperial official. By the end of the reign of Emperor Wen's son Emperor Yang, he was the deputy imperial censor.
In 619, with the Sui state collapsing in light of rebellions around the empire before and after Emperor Yang's death in a coup in 618, the general Wang Shichong, in control of the eastern capital Luoyang, deposed the last Sui emperor, Emperor Yang's grandson Yang Tong and declared himself emperor of a new state of Zheng. Wang made Du Yan the minister of civil service affairs and trusted him greatly. Meanwhile, Du Yan's nephew Du Ruhui had become an important advisor to Li Shimin, a son of rival Tang Dynasty's Emperor Gaozu and a major Tang general. Du Ruhui's older brother and younger brother Du Chuke were at Luoyang at that time, under Zheng rule. Du Yan had poor relations with his nephews, and he decided to act against them. He falsely accused them before Wang, and Wang executed Du Ruhui's older brother and imprisoned Du Chuke. Du Chuke almost starved to death but survived the imprisonment. In 621, Li Shimin put Luoyang under siege and, after defeating Wang's ally Dou Jiande the Prince of Xia, forced Wang to surrender. Li Shimin spared Wang, but executed a number of his high-level officials. Du Yan was initially set to be executed. Du Chuke asked Du Ruhui to intercede on Du Yan's behalf, and Du Ruhui initially refused. Du Chuke, however, pointed out that while Du Yan was responsible for their older brother's death, he was an uncle. Du Ruhui relented and pleaded with Li Shimin on Du Yan's behalf, and Du Yan was spared.
During Emperor Gaozu's reign
Du Yan apparently became a minor official in the imperial administration, but was not promoted. Eventually, he considered resigning and joining the staff of Li Shimin's older brother Li Jianchengthe Crown Prince—with whom Li Shimin was then having an intense rivalry. The official in charge of civil service affairs at that time, Feng Deyi, informed Li Shimin's chief strategist Fang Xuanling of this, and Fang, knowing that Du was intelligent and full of strategies, feared that Du, if he joined Li Jiancheng's staff, would cause detriment to Li Shimin, and therefore persuaded Li Shimin to invite Du to join his staff. Du accepted the invitation. In 624, there was an incident where Li Jiancheng was discovered to have, against regulations, recruited additional soldiers for his guard corps. Emperor Gaozu was angry and put Li Jiancheng under house arrest for a time. He also considered creating Li Shimin crown prince instead to replace Li Jiancheng. Li Jiancheng's guard commander, Yang Wen'gan, in fear, rose in rebellion. Li Shimin and the other generals quickly defeated and killed Yang. However, with the intercession of another son -- Li Yuanji the Prince of Qi, Feng, and his concubines, Emperor Gaozu changed his mind and did not depose Li Jiancheng. Instead, he blamed Li Jiancheng's staff member Wang Gui and two of Li Shimin's staff members—Du and Wei Ting -- of inciting the brothers to struggle against each other. He exiled Wang, Du, and Wei to Xi Prefecture. Before Du departed, Li Shimin, believing that Du was unfairly blamed, gave him a substantial gift of gold.
During Emperor Taizong's reign
In 626, Li Shimin ambushed Li Jiancheng and Li Yuanji at Xuanwu Gate and killed them. He then effectively forced Emperor Gaozu to first create him crown prince and then yield the throne to him. Emperor Taizong recalled Du Yan from exile, made him the imperial censor, and created him the Duke of Anji. Emperor Taizong made Du in charge of the creation ceremony for his son and crown prince Li Chengqian, and in 627 made him the minister of civil service affairs. He also bestowed Du with the additional designation of Canyu Chaozheng -- a de facto chancellor designation. It was said that in these capacities, Du recommended more than 40 people to be imperial officials, and many of them were later known for good service. There was a famous exchange between Emperor Taizong and Du involving Du's recommendation of a minor imperial official, Di Daohuai. As the Old Book of Tang recorded, this was the conversation: At that time, Du was in multiple posts, but was not known for being honest. He was also discordant with Zhangsun Wuji, and his reputation suffered. When he later became ill, Emperor Taizong personally visited him and bestowed a gift of silk on him. He died in 628.