Yan was born in Wannian (, in modern
Xi'an, Shaanxi). His ancestors were originally from
Langya (modern-day
Linyi, Shandong). Yan's grandfather
Yan Zhitui was an official under the
Northern Qi. After the fall of Northern Qi, Zhitui became an official of the
Northern Zhou, and moved his family to
Guanzhong. His son
Yan Silu, Yan's father, was also an official, and served in the residence of
Li Shimin, future
Emperor Taizong. Yan was well-read during his youth and was familiar with philology. Recommended by Li Gang (), he was given a post at Anyang county (now
Xiangyang, Hubei) during the reign of
Emperor Wen of Sui. One of his father's old friends, Xue Daoheng (), was impressed by Yan's talent, and often asked for his comments on his new works. For some reason, Yan Shigu was later dismissed, and took up residence at
Chang'an. During the next ten years, he lived in poverty and taught for a living. He was later granted several important official posts during the
Tang dynasty. Yan was promoted when Li Shimin ascended the throne, but resumed his duty after his mother's funeral. After years of struggle, Yan was then demoted, but was subsequently ordered to revise the
Five Classics in the imperial library. He wrote commentaries on several
Chinese classic texts such as the
Shiji and the
Book of Han. According to the
New Book of Tang, he died on the road during an expedition to
Goguryeo in 645. ==Ancestors and descendants==