The prompt engine is responsible for generating prompt templates based on the user query and the type of prompt required. The prompt templates are then passed to the retriever, which uses them to retrieve relevant data from the source database. The prompt engine also performs validation on the user query to ensure that it is safe to be sent to the retriever.