More explicit error message when using the derivative of an external function in the model block.

Closes #678

(cherry picked from commit 31a14262773d21aa8c7df5209c698bbabbac8bde)