You should not call sqlite3_result_* from within the step function of an aggregate. Those routines may be called from within the finalizer function only.
Could you add some sort of assertion so that it is caught if the functions are called? So what should I do if an error occurs? Since I am ultimately running a user provided Python function there is always the possibility of an error happening. Roger