### How to ask the user for legal inputs?

Suppose we have the following code for the Taylor expansion.

```
@interact
def Taylor(
f = input_box(default=e^x ),
n = slider(vmin=0, vmax=10, step_size=1, default=3, label="Select the order n: ")):
print (f, " = " , f.taylor(x, 0, n))
```

Then we will get a Sage Interact. We can change the function e^x to any function of x and get the Taylor expansion.

However if we input something like e^y, we will get an error from Sage.

Is there some way that we can modify the code so that if someone input something which is not a function of x, it will print "illegal input" instead of returning an error?

More generally, if I require the input to be an element of a polynomial ring, for example Q[x,y,z], then how to ask Sage to print "illegal input" if someone input something like t^2.