Hi Arkyadeep,
Not sure if I understood your problem, but it appears that you allow the user to customize the SQL and that will affect the output and you are getting a mismatch error because of that.
The only workaround I know for this is for you the define the output of your SQL as a structure that has more fields that the user will ever need. Having a structure with more attributes than what is returned from the DB is okay.
Regards,
Rúben