According to official accounts, Tuoba Gui was born in 371, after his father Tuoba Shi (), the son and heir apparent to Tuoba Shiyijian the Prince of Dai, died earlier in the year from an injury he suffered while protecting Tuoba Shiyijian from an assassination attempt by the general Baba Jin (). His mother was Tuoba Shi's wife Heiress Apparent Helan, the daughter of the powerful tribal chief and Dai vassal Helian Yegan (). Tuoba Shiyijian, while mourning his son's death, was very pleased by the grandson's birth, and he declared a general pardon in his state and named the child Tuoba Shegui. (Other than the reference to the naming at birth, however, the name "Shegui" was scantily mentioned in historical accounts of the rest of his life, and presumably was shortened to "Gui" for simplicity.)