Mishkat al-Masabih 2433
وَعَنْ أَبِي هُرَيْرَةَ قَالَ: قَالَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ: مَنْ جَلَسَ مَجْلِسًا فَكَثُرَ فِيهِ لَغَطُهُ فَقَالَ قَبْلَ أَنْ يَقُومَ: سُبْحَانَكَ اللَّهُمَّ وَبِحَمْدِكَ أَشْهَدُ أَنْ لَا إِلَهَ إِلَّا أَنْتَ أَسْتَغْفِرُكَ وَأَتُوبُ إِلَيْكَ إِلَّا غُفِرَ لَهُ مَا كَانَ فِي مَجْلِسِهِ ذَلِكَ . رَوَاهُ التِّرْمِذِيّ وَالْبَيْهَقِيّ فِي الدَّعْوَات الْكَبِير
From Abu Hurayrah, who said: The Messenger of Allah ﷺ said: "Whoever sits in a gathering in which there is much idle talk, and says before he gets up: Glorified are You, O Allah, and praised. I bear witness that there is no god but You. I seek Your forgiveness and repent to You, will be forgiven whatever happened in that gathering of his." Reported by at-Tirmidhi and al-Bayhaqi in ad-Daʿawat al-Kabir.