Well, you write a complete version of a set of symbolic tools, that can parse any function provided, and know the rules for differentiation. You will need to put all possible functions in, and know how to differentiate them, for example sin(x), etc. The chain rule will be necessary. Of course, you will need to implement computer algebra too, so adds, subtracts, multiplies, divides, powers.
Are you sure you are up to it? For example, I did much of what you want to do, but only for a very simple class of functions - symbolic polynomials. It is doable. You can look at what I did in the sympoly toolbox, since it is available for free download from the file exchange.
The answer will be to be careful, in that you need to limit what you implement. Don't try to write a complete set of tools that can handle ANYTHING. It will fail if you try to be too exhaustive. So start small, and accept that you could add capability with time.