Refactoring prompt building into a callback function.