When the drop of (semen) remains in the womb for forty or forty five nights, the angel comes and says: My Lord, will he be good or evil? And both these things would be written. Then the angel says: My Lord, would he be male or female? And both these things are written. And his deeds and actions, his death, his livelihood; these are also recorded. Then his document of destiny is rolled and there is no addition to nor subtraction from it. (Using translation from Muslim 2644)
عَنِ النَّبِيِّ ﷺ قَالَ يَدْخُلُ الْمَلَكُ عَلَى النُّطْفَةِ بَعْدَمَا تَسْتَقِرُّ فِي الرَّحِمِ أَرْبَعِينَ أَوْ خَمْسًا وَأَرْبَعِينَ لَيْلَةً فَيَقُولُ أَيْ رَبِّ أَشَقِيٌّ أَمْ سَعِيدٌ؟ فَيَقُولُ اللهُ ﷻ وَيَكْتُبانِ أَذَكَرٌ أَمْ أُنْثَى؟ فَيَقُولُ اللهُ وَيَكْتُبَانِ مُصِيبَتَهُ وَأَثَرَهُ وَرِزْقَهُ وَأَجَلَهُ ثُمَّ تُطْوَى الصَّحِيفَةُ فَلَا يُزَادُ فِيهَا أَوْ يُنْقَصُ مِنْهَا