The Messenger of Allah ﷺ said, "Indeed, some poetry contains wisdom."
أن رسول الله ﷺ قال: إن من الشعر حكمة.
No references are available.
Bukhari narrated it in al-Adab (6145) from Abu Yaman, who said, Shuayb told us, from Zuhri, who said, Abu Bakr bin Abdul-Rahman told me that Marwan bin Hakam told him that Abdul-Rahman bin Aswad bin Abdu Yaghuth told him that Ubayy bin Kaab told him, and he mentioned it.