I find it's often useful to include the actual query string in the error output to help identify where the problem is. Therefore you might want to add an (optional?) parameter to your confirm_query() function so that you can pass it the query string, and then have it output that string in the error message.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation