Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
bayhaqi:9180Abū ʿAbdullāh al-Ḥāfiẓ > Abū Jaʿfar Aḥmad b. ʿUbayd b. Ibrāhīm al-Ḥāfiẓ Bihamdān > Ibrāhīm b. al-Ḥusayn > Abū al-Yamān > Shuʿayb > al-Zuhrī > Abū Bakr b. ʿAbd al-Raḥman b. al-Ḥārith b. Hishām > Marwān b. al-Ḥakam > ʿAbd al-Raḥman b. al-Aswad b. ʿAbd Yaghūth > Ubī b. Kaʿb al-Anṣārī

[Machine] He informed him that the Prophet ﷺ said, "Indeed, there is wisdom in poetry."  

البيهقي:٩١٨٠أَخْبَرَنَا أَبُو عَبْدِ اللهِ الْحَافِظُ أنبأ أَبُو جَعْفَرٍ أَحْمَدُ بْنُ عُبَيْدِ بْنِ إِبْرَاهِيمَ الْحَافِظُ بِهَمْدَانَ ثنا إِبْرَاهِيمُ بْنُ الْحُسَيْنِ ثنا أَبُو الْيَمَانِ ثنا شُعَيْبٌ عَنِ الزُّهْرِيِّ أَخْبَرَنِي أَبُو بَكْرِ بْنُ عَبْدِ الرَّحْمَنِ بْنِ الْحَارِثِ بْنِ هِشَامٍ أَنَّ مَرْوَانَ بْنَ الْحَكَمِ أَخْبَرَهُ أَنَّ عَبْدَ الرَّحْمَنِ بْنَ الْأَسْوَدِ بْنِ عَبْدِ يَغُوثَ أَخْبَرَهُ أَنَّ أُبِيَّ بْنَ كَعْبٍ الْأَنْصَارِيَّ

أَخْبَرَهُ أَنَّ النَّبِيَّ ﷺ قَالَ إِنَّ مِنَ الشِّعْرِ حِكْمَةً  

رَوَاهُ الْبُخَارِيُّ فِي الصَّحِيحِ عَنْ أَبِي الْيَمَانِ

See similar narrations below:

Collected by Bukhārī
bukhari:6145Abū al-Yamān > Shuʿayb > al-Zuhrī > Abū Bakr b. ʿAbd al-Raḥman > Marwān b. al-Ḥakam > ʿAbd al-Raḥman b. al-Aswad b. ʿAbd Yaghūth > Ubay b. Kaʿb

Messenger of Allah ﷺ said, "Some poetry contains wisdom."  

البخاري:٦١٤٥حَدَّثَنَا أَبُو الْيَمَانِ أَخْبَرَنَا شُعَيْبٌ عَنِ الزُّهْرِيِّ قَالَ أَخْبَرَنِي أَبُو بَكْرِ بْنُ عَبْدِ الرَّحْمَنِ أَنَّ مَرْوَانَ بْنَ الْحَكَمِ أَخْبَرَهُ أَنَّ عَبْدَ الرَّحْمَنِ بْنَ الأَسْوَدِ بْنِ عَبْدِ يَغُوثَ أَخْبَرَهُ أَنَّ أُبَىَّ بْنَ كَعْبٍ

أَخْبَرَهُ أَنَّ رَسُولَ اللَّهِ ﷺ قَالَ إِنَّ مِنَ الشِّعْرِ حِكْمَةً