(Imām Bukhārī narrates): Musaddad narrated to us, he said: Hammad narrated to us, from Ubaidullah bin Abi Bakr, from Hazrat Anas bin Malik (may Allāh be pleased with him), from the Prophet ﷺ, he said:
Indeed, Allāh, Mighty and Sublime, has appointed an angel over the womb, who says: O my Lord! A drop of semen; O my Lord! A clot of blood; O my Lord! A lump of flesh. Then when Allāh intends to create it, the angel asks: Male or female? Wretched or fortunate? What is its provision? And what is the duration of its life? Then all this is written while it is in its mother's womb.
حَدَّثَنَا مُسَدَّدٌ، قَالَ حَدَّثَنَا حَمَّادٌ، عَنْ عُبَيْدِ اللَّهِ بْنِ أَبِي بَكْرٍ، عَنْ أَنَسِ بْنِ مَالِكٍ، عَنِ النَّبِيِّ صَلَّى اللهُ عَلَيْهِ وَسَلَّمَ
قَالَ: "إِنَّ اللَّهَ عَزَّ وَجَلَّ وَكَّلَ بِالرَّحِمِ مَلَكًا يَقُولُ: يَا رَبِّ نُطْفَةٌ، يَا رَبِّ عَلَقَةٌ، يَا رَبِّ مُضْغَةٌ، فَإِذَا أَرَادَ أَنْ يَقْضِيَ خَلْقَهُ قَالَ: أَذَكَرٌ أَمْ أُنْثَى، شَقِيٌّ أَمْ سَعِيدٌ، فَمَا الرِّزْقُ وَالأَجَلُ، فَيُكْتَبُ فِي بَطْنِ أُمِّهِ".
Reference: Sahih Al Bukhari 318